php阻塞请求nginx,Windows下nginx+fastcgi+php的并发阻塞问题

首先在nginx.conf中进行如下配置:

worker_processes 1;

events {

worker_connections 1024;

}

http {

include mime.types;

default_type application/octet-stream;

sendfile on;

keepalive_timeout 60;

underscores_in_headers on;

include otherconf/*.conf;

include hlyunbackend/*.conf;

client_max_body_size 20m;

add_header Access-Control-Allow-Origin *;

add_header Access-Control-Allow-Headers X-Requested-With;

add_header Access-Control-Allow-Methods GET,POST,PUT,DELETE,OPTIONS;

#额外启动多个php-cgi去处理并发请求

upstream fastcgi_proxy{

server 127.0.0.1:9000;

server 127.0.0.1:9001;

server 127.0.0.1:9002;

server 127.0.0.1:9003;

server 127.0.0.1:9004;

server 127.0.0.1:9005;

server 127.0.0.1:9006;

server 127.0.0.1:9007;

server 127.0.0.1:9008;

server 127.0.0.1:9009;

server 127.0.0.1:9010;

server 127.0.0.1:9011;

server 127.0.0.1:9012;

server 127.0.0.1:9013;

server 127.0.0.1:9014;

server 127.0.0.1:9015;

server 127.0.0.1:9016;

server 127.0.0.1:9017;

server 127.0.0.1:9018;

server 127.0.0.1:9019;

server 127.0.0.1:9020;

server 127.0.0.1:9021;

server 127.0.0.1:9022;

server 127.0.0.1:9023;

server 127.0.0.1:9024;

server 127.0.0.1:9025;

}

}

再把所有

fastcgi_pass 127.0.0.1:9000;

改为

fastcgi_pass phpfastcgi_proxy;

server {

listen 7000;

server_name localhost;

location / {

add_header Access-Control-Allow-Origin *;

add_header Access-Control-Allow-Headers X-Requested-With;

add_header Access-Control-Allow-Methods GET,POST,PUT,DELETE,OPTIONS;

root E:/www/htms3/hlyun_sso/public;

index index.html index.htm index.php;

try_files $uri $uri/ /index.php?$query_string;

}

error_page 500 502 503 504 /50x.html;

location ~ \.php$ {

root E:/www/htms3/hlyun_sso/public;

fastcgi_pass fastcgi_proxy;

fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

include fastcgi_params;

}

}

保存,重启Nginx。

开启cgi端口(.bat 文件):

taskkill /F /IM nginx.exe >nul

taskkill/F /IM php-cgi.exe >nul

@echo off

echo Starting nginx...

E:\nginx\RunHiddenConsole.exe E:\nginx\nginx.exe-p E:\nginx

echo Starting PHP FastCGI...

E:\nginx\RunHiddenConsole.exe C:\php\php-cgi.exe -b 127.0.0.1:9000 -c C:\php\php.ini

E:\nginx\RunHiddenConsole.exe C:\php\php-cgi.exe -b 127.0.0.1:9001 -c C:\php\php.ini

E:\nginx\RunHiddenConsole.exe C:\php\php-cgi.exe -b 127.0.0.1:9002 -c C:\php\php.ini

E:\nginx\RunHiddenConsole.exe C:\php\php-cgi.exe -b 127.0.0.1:9003 -c C:\php\php.ini

E:\nginx\RunHiddenConsole.exe C:\php\php-cgi.exe -b 127.0.0.1:9004 -c C:\php\php.ini

E:\nginx\RunHiddenConsole.exe C:\php\php-cgi.exe -b 127.0.0.1:9005 -c C:\php\php.ini

E:\nginx\RunHiddenConsole.exe C:\php\php-cgi.exe -b 127.0.0.1:9006 -c C:\php\php.ini

E:\nginx\RunHiddenConsole.exe C:\php\php-cgi.exe -b 127.0.0.1:9007 -c C:\php\php.ini

E:\nginx\RunHiddenConsole.exe C:\php\php-cgi.exe -b 127.0.0.1:9008 -c C:\php\php.ini

E:\nginx\RunHiddenConsole.exe C:\php\php-cgi.exe -b 127.0.0.1:9009 -c C:\php\php.ini

E:\nginx\RunHiddenConsole.exe C:\php\php-cgi.exe -b 127.0.0.1:9010 -c C:\php\php.ini

E:\nginx\RunHiddenConsole.exe C:\php\php-cgi.exe -b 127.0.0.1:9011 -c C:\php\php.ini

E:\nginx\RunHiddenConsole.exe C:\php\php-cgi.exe -b 127.0.0.1:9012 -c C:\php\php.ini

E:\nginx\RunHiddenConsole.exe C:\php\php-cgi.exe -b 127.0.0.1:9013 -c C:\php\php.ini

E:\nginx\RunHiddenConsole.exe C:\php\php-cgi.exe -b 127.0.0.1:9014 -c C:\php\php.ini

E:\nginx\RunHiddenConsole.exe C:\php\php-cgi.exe -b 127.0.0.1:9015 -c C:\php\php.ini

E:\nginx\RunHiddenConsole.exe C:\php\php-cgi.exe -b 127.0.0.1:9016 -c C:\php\php.ini

E:\nginx\RunHiddenConsole.exe C:\php\php-cgi.exe -b 127.0.0.1:9017 -c C:\php\php.ini

E:\nginx\RunHiddenConsole.exe C:\php\php-cgi.exe -b 127.0.0.1:9018 -c C:\php\php.ini

E:\nginx\RunHiddenConsole.exe C:\php\php-cgi.exe -b 127.0.0.1:9019 -c C:\php\php.ini

E:\nginx\RunHiddenConsole.exe C:\php\php-cgi.exe -b 127.0.0.1:9020 -c C:\php\php.ini

E:\nginx\RunHiddenConsole.exe C:\php\php-cgi.exe -b 127.0.0.1:9021 -c C:\php\php.ini

E:\nginx\RunHiddenConsole.exe C:\php\php-cgi.exe -b 127.0.0.1:9022 -c C:\php\php.ini

E:\nginx\RunHiddenConsole.exe C:\php\php-cgi.exe -b 127.0.0.1:9023 -c C:\php\php.ini

E:\nginx\RunHiddenConsole.exe C:\php\php-cgi.exe -b 127.0.0.1:9024 -c C:\php\php.ini

E:\nginx\RunHiddenConsole.exe C:\php\php-cgi.exe -b 127.0.0.1:9025 -c C:\php\php.ini

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,我知道你的问题了。针对你的问题,我可以给你一些简单的部署步骤: 1.安装nginxPHP 在CentOS 6.8中安装nginxPHP的方式如下: ``` sudo yum install nginx sudo yum install php-fpm ``` 2.配置nginx 在配置nginx之前,你需要备份一下默认的nginx配置文件。备份命令如下: ``` sudo cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak ``` 然后,你可以通过编辑/etc/nginx/nginx.conf文件来配置nginx。 下面是一个简单的nginx配置示例,可以将它添加到/etc/nginx/nginx.conf文件中: ``` user nginx; worker_processes auto; error_log /var/log/nginx/error.log; pid /run/nginx.pid; events { worker_connections 1024; } http { include /etc/nginx/mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on; keepalive_timeout 65; include /etc/nginx/conf.d/*.conf; server { listen 80; server_name localhost; root /usr/share/nginx/html; index index.php index.html index.htm; location / { try_files $uri $uri/ /index.php; } location ~ \.php$ { try_files $uri =404; fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } } ``` 在这个示例配置中,我们将nginx的根目录设置为/usr/share/nginx/html,并且将index.php添加到默认文档列表中。同时,我们还配置了一个location块,用于处理PHP文件。 3.配置PHP 在配置PHP之前,你需要备份一下默认的php-fpm配置文件。备份命令如下: ``` sudo cp /etc/php-fpm.d/www.conf /etc/php-fpm.d/www.conf.bak ``` 然后,你可以通过编辑/etc/php-fpm.d/www.conf文件来配置PHP。 下面是一个简单的PHP配置示例,可以将它添加到/etc/php-fpm.d/www.conf文件中: ``` [www] user = nginx group = nginx listen = /var/run/php-fpm/php-fpm.sock listen.owner = nginx listen.group = nginx pm = dynamic pm.max_children = 50 pm.start_servers = 5 pm.min_spare_servers = 5 pm.max_spare_servers = 35 ``` 在这个示例配置中,我们将PHP-FPM的用户和组设置为nginx,并将PHP-FPM的监听套接字设置为/var/run/php-fpm/php-fpm.sock。 4.重启服务 完成配置后,你需要重启nginxphp-fpm服务,以使配置生效。重启命令如下: ``` sudo systemctl restart nginx sudo systemctl restart php-fpm ``` 到这里,就完成了nginx+PHP的简单部署。同时,为了进一步提升性能,你可以使用Nginx+PHP+FastCGI加速模式。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值