在我的Ubuntu 12.10服务器上,我升级了PHP到5.5。 在我的wordpress网站得到502错误之后,我做了一些Googlesearch,发现我需要改变我的nginxconfiguration,以匹配php脚本传递到php5-fpm.sock而不是端口9000.所以我改变了我的网站的configuration文件到下面:
# Pass PHP scripts on to PHP-FPM location ~* \.php$ { try_files $uri /index.php; fastcgi_index index.php; fastcgi_pass unix:/var/run/php5-fpm.sock; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param SCRIPT_NAME $fastcgi_script_name; fastcgi_buffer_size 16k; fastcgi_buffers 4 16k; }
然后我service nginx restart 。 但502错误仍然存在。
在检查错误日志时,我得到:
2014/03/30 14:16:37 [error] 1451#0: *21 connect() failed (111: Connection refused) while connecting to upstream, client: 81.107.86.251,, server: www.harryg.me, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "harryg.me"
所以看起来像php-fpm正在尝试将东西传递给fastcgi://127.0.0.1:9000 。 为什么不服从configuration文件更改?
编辑:
我的/etc/php5/fpm/pool.d/www.conf有listen = /var/run/php5-fpm.sock 。
我也有这个问题,我通过使用TCP连接解决它。 引用这个答案nginx + php5-fpm中的错误502 (在danmash的链接之后find):
问题是套接字本身,它在高负载情况下的问题是众所周知的。 请考虑使用TCP \ IP连接而不是unix套接字,因为您需要进行这些更改:
- 在php-fpm池configuration中,用
listen = 127.0.0.1:7777replacelisten = /var/run/php5-fpm.sock- 在/ etc / nginx / php_location中replace
fastcgi_pass unix:/var/run/php5-fpm.sock;用fastcgi_pass 127.0.0.1:7777;
在你的情况下,它将是127.0.0.1:9000 。
Nginx错误502代表代理服务器closures或没有返回任何数据或有效的数据。 确保没有nginx或代理代码本身工作正常。 有关详细说明,请查看nginx和phplogin请求。