connect() failed (111: Connection refused) while connecting to upstream, client: 111.199.84.121, s
配置好lnmp後,在瀏覽器中執行程式後,出現上面的錯誤。
轉自:http://www.xuejiehome.com/blread-1828.html
I'm experiencing 502 gateway errors when accessing a PHP file in a directory (http://domain.com/dev/index.php), the logs simply says this:
2011/09/30 23:47:54 [error] 31160#0: *35 connect() failed (111: Connection refused) while connecting to upstream, client: xx.xx.xx.xx, server: domain.com, request: \"GET /dev/ HTTP/1.1\", upstream: \"fastcgi://127.0.0.1:9000\", host: \"domain.com\"
The answer:
It sounds like you haven't started and configured backend for Nginx. Start php-fpm and add the following to nginx.conf, in http context:
server { listen 127.0.0.1; server_name localhost; error_log /var/log/nginx/localhost.error_log info; root /usr/local/nginx/html; location ~ \\.php$ { root html;#此處和server下面root保持一致,預設為html fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html/$fastcgi_script_name; include fastcgi_params; } }
大概意思是你沒有啟動或者配置php-fpm.其中“/usr/local/nginx/html”為網站根目錄。
而我剛好是沒有啟動php-fpm,在終端執行“service php-fpm start”;
如何開啟php-fpm還有點問題
檢視php-fpm的地址
whereis php-fpm
啟動php-fpm
/usr/local/php5/sbin/php-fpm # /usr/local/php5/為php-fpm的安裝地址
/usr/local/php-5.6.3/sbin/php-fpm -R # 如果報錯顯示不能用root使用者啟動,則可以考慮使用 -R命令
檢視是否啟動成功:
netstat -lnt | grep 9000
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN
或者使用如下命令,檢視是否9000埠被php-fpm佔用:
netstat -tunpl | grep 9000
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 2124/php-fpm
php-fpm 關閉:
kill -INT `cat /usr/local/php5/var/run/php-fpm.pid`
或者:pkill php-fpm
---------------------
作者:崖邊樹
來源:CSDN
原文:https://blog.csdn.net/u010716097/article/details/71908096
版權宣告:本文為博主原創文章,轉載請附上博文連結!