問題:connect() failed (111: Connection refused) while connecting to upstream

問題描述:

    服務器重啓之後,服務器也正常運行,發現網站訪問不了,後來查看nginx 錯誤日誌(/var/log/nginx/error.log )

2016/05/13 10:47:32 [error] 7688#0: *8 connect() failed (111: Connection refused) while connecting to upstream, client: ****.****.****.33, server: , request: "GET url HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "****.leyue.com.cn:22080"



後來google,發現類似不少的問題,就整理了一下,基本上有以下三個原因造成這個問題的原因:

>>>php-fpm沒有安裝


>>>php-fpm沒有運行

可以用ps aux | grep 'php-fpm',來查看.
[root@dev ~]# ps aux | grep 'php-fpm'
root      4570  0.0  0.1 612024  7820 ?        Ss   May12   0:04 php-fpm: master process (/etc/php-fpm.conf)
fpmport   4571  0.0  0.0 611620  5864 ?        S    May12   0:00 php-fpm: pool port           
fpmport   4572  0.0  0.0 611620  5892 ?        S    May12   0:00 php-fpm: pool port           
......

如果沒有運行,使用啓動:
/etc/init.d/php-fpm start


>>>php-fpm隊列滿了

php-fpm.conf (/etc/php-fpm.conf)配置文件pm.max_children修改大一點,重啓php-fpm並觀察日誌情況
cd


也看到一個,端口被佔用的情況:

nginx的error日誌裏經常報錯

2011/09/27 13:03:47 [error] 17493#0: *7438996 connect() failed (111: Connection refused) while connecting to upstream, client: 180.168.109.106, server: mysite.com, request: "GET /favicon.ico HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "mysite.com"
2011/09/27 13:03:48 [error] 17493#0: *7438996 connect() failed (111: Connection refused) while connecting to upstream, client: 180.168.109.106, server: mysite.com, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "mysite.com"
2011/09/27 13:03:49 [error] 17493#0: *7438996 connect() failed (111: Connection refused) while connecting to upstream, client: 180.168.109.106, server: mysite.com, request: "GET /favicon.ico HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "mysite.com"

php-fpm的 ERROR級別的日誌是, 

[27-Sep-2011 12:08:02] ERROR: bind() for address '127.0.0.1:9000' failed: Address already in use (98)
[27-Sep-2011 12:30:04] ERROR: bind() for address '127.0.0.1:9000' failed: Address already in use (98)
[27-Sep-2011 12:40:04] ERROR: bind() for address '127.0.0.1:9000' failed: Address already in use (98)
[27-Sep-2011 12:50:04] ERROR: bind() for address '127.0.0.1:9000' failed: Address already in use (98)
[27-Sep-2011 12:57:04] ERROR: bind() for address '127.0.0.1:9000' failed: Address already in use (98)
[27-Sep-2011 13:03:04] ERROR: bind() for address '127.0.0.1:9000' failed: Address already in use (98)
[27-Sep-2011 13:03:04] ERROR: bind() for address '127.0.0.1:9000' failed: Address already in use (98)

偶爾出現
[26-Sep-2011 17:48:24] ERROR: ptrace(PEEKDATA) failed: Input/output error (5)
[26-Sep-2011 17:49:04] ERROR: bind() for address '127.0.0.1:9000' failed: Address already in use (98)
[26-Sep-2011 17:49:32] ERROR: ptrace(PEEKDATA) failed: Input/output error (5)
[26-Sep-2011 17:49:33] ERROR: ptrace(PEEKDATA) failed: Input/output error (5)
[26-Sep-2011 17:49:42] ERROR: ptrace(PEEKDATA) failed: Input/output error (5)


原因:

ERROR: bind() for address '127.0.0.1:9000' failed: Address already in use (98)
很明顯9000端口被佔用。
3個解決辦法
1 在nginx.conf中換個php的端口試試
2 實在不行還有sock方式。
3 殺死那個佔用9000端口的程序。


2>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章