检查状态:

检查状态:

您必须原谅我的无能,我仍在学习 Linux,并且正在努力学习这个。我在 AWS 上托管一个网站,该网站在 LEMP 堆栈中运行 Ubuntu,昨晚升级 Ubuntu 后,该网站随机关闭并保持数小时后才恢复。我目前在网站上看到 404 错误。

升级的一切似乎都进展顺利,我告诉它保留修改后的配置文件,所以我不明白问题可能是什么。

这是我的 nginx 错误日志的结尾:

    tail -f /var/log/nginx/error.log
2016/12/09 16:00:24 [error] 1242#1242: *237520 connect() to unix:/var/run/php/php7.0-fpm.sock failed (11: Resource temporarily unavailable) while connecting to upstream, client: 51.15.50.51, server: 52.86.172.123, request: "POST /xmlrpc.php HTTP/1.0", upstream: "fastcgi://unix:/var/run/php/php7.0-fpm.sock:", host: "52.86.172.123"
2016/12/09 16:00:24 [error] 1242#1242: *237520 open() "/usr/share/nginx/www/50x.html" failed (2: No such file or directory), client: 51.15.50.51, server: 52.86.172.123, request: "POST /xmlrpc.php HTTP/1.0", upstream: "fastcgi://unix:/var/run/php/php7.0-fpm.sock", host: "52.86.172.123"
2016/12/09 16:00:24 [error] 1242#1242: *237522 connect() to unix:/var/run/php/php7.0-fpm.sock failed (11: Resource temporarily unavailable) while connecting to upstream, client: 51.15.51.63, server: 52.86.172.123, request: "POST /xmlrpc.php HTTP/1.0", upstream: "fastcgi://unix:/var/run/php/php7.0-fpm.sock:", host: "52.86.172.123"
2016/12/09 16:00:24 [error] 1242#1242: *237522 open() "/usr/share/nginx/www/50x.html" failed (2: No such file or directory), client: 51.15.51.63, server: 52.86.172.123, request: "POST /xmlrpc.php HTTP/1.0", upstream: "fastcgi://unix:/var/run/php/php7.0-fpm.sock", host: "52.86.172.123"
2016/12/09 16:00:24 [error] 1242#1242: *237524 connect() to unix:/var/run/php/php7.0-fpm.sock failed (11: Resource temporarily unavailable) while connecting to upstream, client: 54.90.195.202, server: 52.86.172.123, request: "POST /wp-cron.php?doing_wp_cron=1481299224.7692439556121826171875 HTTP/1.1", upstream: "fastcgi://unix:/var/run/php/php7.0-fpm.sock:", host: "aftercredits.com", referrer: "http://aftercredits.com/wp-cron.php?doing_wp_cron=1481299224.7692439556121826171875"
2016/12/09 16:00:24 [error] 1242#1242: *237524 open() "/usr/share/nginx/www/50x.html" failed (2: No such file or directory), client: 54.90.195.202, server: 52.86.172.123, request: "POST /wp-cron.php?doing_wp_cron=1481299224.7692439556121826171875 HTTP/1.1", upstream: "fastcgi://unix:/var/run/php/php7.0-fpm.sock", host: "aftercredits.com", referrer: "http://aftercredits.com/wp-cron.php?doing_wp_cron=1481299224.7692439556121826171875"
2016/12/09 16:00:24 [error] 1242#1242: *237525 connect() to unix:/var/run/php/php7.0-fpm.sock failed (11: Resource temporarily unavailable) while connecting to upstream, client: 54.163.1.126, server: 52.86.172.123, request: "POST /wp-cron.php?doing_wp_cron=1481299224.6867620944976806640625 HTTP/1.1", upstream: "fastcgi://unix:/var/run/php/php7.0-fpm.sock:", host: "aftercredits.com", referrer: "http://aftercredits.com/wp-cron.php?doing_wp_cron=1481299224.6867620944976806640625"
2016/12/09 16:00:24 [error] 1242#1242: *237525 open() "/usr/share/nginx/www/50x.html" failed (2: No such file or directory), client: 54.163.1.126, server: 52.86.172.123, request: "POST /wp-cron.php?doing_wp_cron=1481299224.6867620944976806640625 HTTP/1.1", upstream: "fastcgi://unix:/var/run/php/php7.0-fpm.sock", host: "aftercredits.com", referrer: "http://aftercredits.com/wp-cron.php?doing_wp_cron=1481299224.6867620944976806640625"
2016/12/09 16:00:24 [error] 1242#1242: *237528 connect() to unix:/var/run/php/php7.0-fpm.sock failed (11: Resource temporarily unavailable) while connecting to upstream, client: 51.15.51.63, server: 52.86.172.123, request: "POST /xmlrpc.php HTTP/1.0", upstream: "fastcgi://unix:/var/run/php/php7.0-fpm.sock:", host: "52.86.172.123"

我非常感谢大家的帮助。谢谢!

编辑:这是所请求命令的输出:

/var/run$ cd /var/run; sudo find -name 'php*fpm.sock'
./php/php7.0-fpm.sock

答案1

这里有两个问题。


问题 #1:缺少错误页面。

这是相关的错误行:

2016/12/09 16:00:24 [error] 1242#1242: *237520 open() "/usr/share/nginx/www/50x.html" failed (2: No such file or directory), client: ...

在您的配置中,您已将系统配置为/usr/share/nginx/www/50x.html针对 50X HTTP 错误提供页面。该页面不存在,因此您无法提供该页面。您必须创建该页面。

请注意,使用默认的 docroot/usr/share/nginx/...被视为陷阱因为无法保证包管理器不会覆盖其中的内容。


问题 #2:PHP 正在运行,但找不到套接字。

这些行:

2016/12/09 16:00:24 [error] 1242#1242: *237525 connect() to unix:/var/run/php/php7.0-fpm.sock failed (11: Resource temporarily unavailable) while connecting to upstream, client: ...

所以,这里有些弊端。PHP7.0 可能正在运行,但不在您认为的位置。默认php7.0设置将在或php7.0-fpm中运行,但在我看来,您的情况并非如此。/run/php/php7.0-fpm.sock/var/run/php/php7.0-fpm.sock

首先,检查确保确实有一个套接字文件正在运行。

cd /var/run
find -name 'php*fpm.sock'

如果它返回类似这样的内容,那么我们就知道套接字正在运行,并且应该使用/var/run/[path]该套接字(并且您需要相应地更新 nginx 配置):

php/php7.0-fpm.sock

但是,您可能没有使用套接字文件,而需要使用 TCP 套接字的旧式方法。检查 PHP 套接字是否正在监听端口 9000:

sudo netstat -tulpn | grep 9000

如果是,那么您需要使用,而unix:...不是。fastcgi_pass127.0.0.1:9000

如果两者都不这些产生的结果,那么你需要确保php7.0-fpm它确实在运行:

sudo systemctl restart php7.0-fpm

然后尝试重复这些步骤来验证它是否正在运行。

答案2

我很幸运,能够解决这个问题。我认为还存在一些其他问题,但至少网站已经恢复,而且现在看起来很稳定。

我读到一篇文章,上面说 /etc/php/7.0/fpm/pool.d/www.conf/ listen 条目和 /etc/nginx/sites-available/ fastcgi_pass 需要是相同的值。它们不是。我尝试将它们都设置为“/run/php/php7.0-fpm.sock”,但没有成功。所以我将它们都设置为 127.0.0.1:9000,这似乎成功了。

我无法告诉你为什么之前这一切都能正常工作,是否是升级改变了这些值,或者做了其他相关的事情。但至少现在它可以正常工作了。

答案3

检查状态:

sudo service php7.0-fpm status

或者

sudo systemctl status php7.0-fpm

如果已经运行,请尝试

sudo service php7.0-fpm restart

或者

sudo systemctl reload php7.0-fpm

否则尝试

sudo service php7.0-fpm start

或者

sudo systemctl start php7.0-fpm

相关内容