php 连接到 unix:/var/run/php5-fpm.sock 失败。我的设置有什么问题?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25098029/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 17:39:49  来源:igfitidea点击:

Connect to unix:/var/run/php5-fpm.sock failed. What is wrong with my setup?

phpwordpressnginx

提问by vsapountzis

I have a 2GB VPS on DigitalOcean and I am hosting WordPress 3.9.1 under Debian 7 with NGINX, php-fpm and unix socket.

我在 DigitalOcean 上有一个 2GB 的 VPS,我在 Debian 7 下使用 NGINX、php-fpm 和 unix 套接字托管 WordPress 3.9.1。

It was working perfectly until last week it started showing a "502 bad gateway" error. I checked the logs and found that:

它一直运行良好,直到上周它开始显示“502 错误网关”错误。我检查了日志,发现:

php5-fpm log is showing pm.max_children was reached and nginx log is showing the following:

[error] 3239#0: *15188 connect() to unix:/var/run/php5-fpm.sock failed (11: Resource temporarily unavailable) while connecting to upstream, client: xxx.xxx.xxx.xxx, server: my.domain, request: "POST /xmlrpc.php HTTP/1.0", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "xxx.xxx.xxx.xxx"

php5-fpm 日志显示 pm.max_children 已到达,nginx 日志显示以下内容:

[error] 3239#0: *15188 connect() to unix:/var/run/php5-fpm.sock failed (11: Resource暂时不可用),同时连接到上游,客户端:xxx.xxx.xxx.xxx,服务器: my.domain,请求:“POST /xmlrpc.php HTTP/1.0”,上游:“fastcgi://unix:/var/run/php5-fpm.sock:”,主机:“xxx.xxx.xxx.xxx”

I manually changed pm with different settings with no luck. I always restart the daemons after every change.

我用不同的设置手动更改了 pm ,但没有运气。我总是在每次更改后重新启动守护程序。

pm settings are:

下午设置是:

pm = dynamic 
pm.max_children = 100 
pm.start_servers = 10 
pm.min_spare_servers = 10 
pm.max_spare_servers = 10 
pm.max_requests = 200

www.confhas the listen = /var/run/php5-fpm.sockenabled.

www.conflisten = /var/run/php5-fpm.sock启用。

Anyone with a similar experience?

有类似经历的人吗?

回答by Rijndael

The first problem is you are specifying 100 max_children, that is awfully high for 2GB. I would drop it to 25 children. See my post here on how to optimise your php-fpm configuration for your setup:

第一个问题是您指定了 100 个 max_children,这对于 2GB 来说非常高。我会把它放到 25 个孩子身上。请参阅我的帖子,了解如何为您的设置优化 php-fpm 配置:

WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning

警告:[pool www] 似乎很忙(您可能需要增加 pm.start_servers 或 pm.min/max_spare_servers),正在生成

Also, using unix sockets is slightly faster since it provides you direct network access without any TCP/IP overhead. On the down side, it is not as scalable as TCP/IP. Nginx will throw 502 errors when the sockets have been depleted. In such a case you can either tweak the OS settings to accommodate the larger connection pool or just switch to switch to TCP/IP.

此外,使用 unix 套接字稍微快一些,因为它为您提供直接网络访问,而无需任何 TCP/IP 开销。不利的一面是,它不像 TCP/IP 那样可扩展。当套接字耗尽时,Nginx 将抛出 502 错误。在这种情况下,您可以调整操作系统设置以适应更大的连接池,或者只是切换到 TCP/IP。

In your fastcgi conf change:

在您的 fastcgi conf 更改中:

fastcgi_pass unix:/var/run/php5-fpm.sock;

to:

到:

fastcgi_pass 127.0.0.1:9000;

Note that port 9000 is the default port set in php-fpm, if you have changed php-fpm to listen on another port then swap 9000 with that value. Make sure you restart both php-fpm and nginx.

请注意,端口 9000 是 php-fpm 中设置的默认端口,如果您已将 php-fpm 更改为侦听另一个端口,则将 9000 与该值交换。确保重新启动 php-fpm 和 nginx。

Now, if after all of this, you still cannot get it to work and free -mreturns high memory usage, then it is time to add more ram to your server.

现在,如果在所有这些之后,您仍然无法使其工作并且free -m返回高内存使用率,那么是时候向您的服务器添加更多内存了。