更换Apache扑向Nginx,刚搭建完WNMP,nginx能访问php页面 但是访问现有开发项目报错
1 [error] 4112#3724: *9 upstream timed out (10060: A connection attempt failed because the connected party did not properly respond 2 after a period of time, or established connection failed because connected host has failed to respond) while reading response header 3 from upstream, client: 127.0.0.1, server: localhost, request: "GET /right/backend/web/index.php?r=api/get-products HTTP/1.1", 4 upstream: "fastcgi://127.0.0.1:9000", host: "127.0.0.1"
通过探寻 找到原因 当前使用的是项目A,但是A调用了项目B(权限系统) 但是配置的Nginx时只固定了一个9000端口 A占用后;B就无法访问
解决方案:
1.修改nginx.conf 添加端口(红色部分)
http { include 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 logs/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; gzip on; upstream fastcgi_backend { 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 { listen 80; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / { root D:/WNMP/nginx-1.10.3/html; index index.html index.htm index.php; autoindex on; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root D:/WNMP/nginx-1.10.3/html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ .php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ .php$ { # root D:/WNMP/nginx-1.10.3/html; fastcgi_pass fastcgi_backend; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME D:/WNMP/nginx-1.10.3/html$fastcgi_script_name; include fastcgi_params; } # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /.ht { # deny all; #} }
2.如果使用快捷脚本启动WNMP,脚本修改(可以将php nginx加入环境变量使用相对路径,我用的绝对路径哈,因为项目多,方便应用不同php版本)
@echo off start /B D:/WNMP/php7/php-cgi.exe -b 127.0.0.1:9001 & start /B D:/WNMP/php7/php-cgi.exe -b 127.0.0.1:9002 & start /B D:/WNMP/php7/php-cgi.exe -b 127.0.0.1:9003 & start /B D:/WNMP/php7/php-cgi.exe -b 127.0.0.1:9004 & start /B D:/WNMP/php7/php-cgi.exe -b 127.0.0.1:9005 & start /B D:/WNMP/php7/php-cgi.exe -b 127.0.0.1:9006 & start /B D:/WNMP/php7/php-cgi.exe -b 127.0.0.1:9007 & start /B D:/WNMP/nginx/nginx.exe