PHP-FPM和Nginx:proxy_error_log

时间:2016-10-02 16:14:15

标签: php linux apache nginx centos

我发现了4年前发布的以下讨论:502 Gateway Errors under High Load (nginx/php-fpm)

如果有人遇到与我类似的问题,但不幸的是我相信他收到的配置是根据自己的服务器规格定制的,我不能在我的服务器上使用相同的配置。无论如何,我想提出我自己的问题而不是只是告诉你去我发送的链接并阅读其他人的问题。

所以对于我自己的故事 - 我有一个很大的社交媒体页面,我发布链接到我的网站文章,这意味着我每天分享一些东西时有很多流量峰值。最近我注意到该网站太慢,有时根本没有加载,不幸的是我不太熟悉解决这样的问题而且我没有管理我的专用服务器的系统管理员,因为我从OVH租用它它以低成本提供非托管服务器。服务器具有相当不错的规格,即使现场有100个活跃用户,也会出现此问题。我还可以在服务器日志中看到一些错误。

服务器规格如下:

AMD Opteron(TM)处理器4334,AMD Opteron(TM)处理器4334(6核)

SoftRaid 3x160GB SSD

32GB RAM

1Gbps连接

CentOS x64 Linux版本7.2.1511(核心)

Plesk v12.5.30

我正在谈论的错误:

proxy_error_log

2016/10/02 09:49:36 [error] 6931#0: *469804 connect() to unix:///var/www/vhosts/system/###.com/php-fpm.sock failed (11: Resource temporarily unavailable) while connecting to upstream, client: 2607:5300:60:5e68::, server: ###.com, request: "POST /wp-cron.php?doing_wp_cron=1475416176.6522459983825683593750 HTTP/1.1", upstream: "fastcgi://unix:///var/www/vhosts/system/###.com/php-fpm.sock:", host: "www.###.com", referrer: "http://www.###.com/wp-cron.php?doing_wp_cron=1475416176.6522459983825683593750"
2016/10/02 09:49:36 [error] 6931#0: *469806 connect() to unix:///var/www/vhosts/system/###.com/php-fpm.sock failed (11: Resource temporarily unavailable) while connecting to upstream, client: 2607:5300:60:5e68::, server: ###.com, request: "POST /wp-cron.php?doing_wp_cron=1475416176.8384990692138671875000 HTTP/1.1", upstream: "fastcgi://unix:///var/www/vhosts/system/###.com/php-fpm.sock:", host: "www.###.com", referrer: "http://www.###.com/wp-cron.php?doing_wp_cron=1475416176.8384990692138671875000"
2016/10/02 09:49:38 [error] 6931#0: *469826 connect() to unix:///var/www/vhosts/system/###.com/php-fpm.sock failed (11: Resource temporarily unavailable) while connecting to upstream, client: 73.77.251.156, server: ###.com, request: "GET /###/ HTTP/1.1", upstream: "fastcgi://unix:///var/www/vhosts/system/###.com/php-fpm.sock:", host: "www.###.com", referrer: "http://m.facebook.com/"
2016/10/02 09:49:38 [error] 6931#0: *469830 connect() to unix:///var/www/vhosts/system/###.com/php-fpm.sock failed (11: Resource temporarily unavailable) while connecting to upstream, client: 217.123.129.73, server: ###.com, request: "GET /###/ HTTP/1.1", upstream: "fastcgi://unix:///var/www/vhosts/system/###.com/php-fpm.sock:", host: "www.###.com", referrer: "http://m.facebook.com/"
2016/10/02 09:49:39 [error] 6931#0: *469840 connect() to unix:///var/www/vhosts/system/###.com/php-fpm.sock failed (11: Resource temporarily unavailable) while connecting to upstream, client: 2607:5300:60:5e68::, server: ###.com, request: "POST /wp-cron.php?doing_wp_cron=1475416179.1317949295043945312500 HTTP/1.1", upstream: "fastcgi://unix:///var/www/vhosts/system/###.com/php-fpm.sock:", host: "www.###.com", referrer: "http://www.###.com/wp-cron.php?doing_wp_cron=1475416179.1317949295043945312500"
2016/10/02 09:49:39 [error] 6931#0: *469842 connect() to unix:///var/www/vhosts/system/###.com/php-fpm.sock failed (11: Resource temporarily unavailable) while connecting to upstream, client: 2605:6001:f08a:3400:88d6:8b94:4499:8e36, server: ###.com, request: "GET /###/ HTTP/1.1", upstream: "fastcgi://unix:///var/www/vhosts/system/###.com/php-fpm.sock:", host: "www.###.com", referrer: "http://m.facebook.com/"
2016/10/02 09:49:39 [error] 6931#0: *469845 connect() to unix:///var/www/vhosts/system/###.com/php-fpm.sock failed (11: Resource temporarily unavailable) while connecting to upstream, client: 162.158.75.61, server: ###.com, request: "GET /###/ HTTP/1.1", upstream: "fastcgi://unix:///var/www/vhosts/system/###.com/php-fpm.sock:", host: "www.###.com", referrer: "http://m.facebook.com/"
2016/10/02 09:49:39 [error] 6931#0: *469847 connect() to unix:///var/www/vhosts/system/###.com/php-fpm.sock failed (11: Resource temporarily unavailable) while connecting to upstream, client: 2607:5300:60:5e68::, server: ###.com, request: "POST /wp-cron.php?doing_wp_cron=1475416179.6054229736328125000000 HTTP/1.1", upstream: "fastcgi://unix:///var/www/vhosts/system/###.com/php-fpm.sock:", host: "www.###.com", referrer: "http://www.###.com/wp-cron.php?doing_wp_cron=1475416179.6054229736328125000000"
2016/10/02 09:49:39 [error] 6931#0: *469849 connect() to unix:///var/www/vhosts/system/###.com/php-fpm.sock failed (11: Resource temporarily unavailable) while connecting to upstream, client: 2607:5300:60:5e68::, server: ###.com, request: "POST /wp-cron.php?doing_wp_cron=1475416179.6478641033172607421875 HTTP/1.1", upstream: "fastcgi://unix:///var/www/vhosts/system/###.com/php-fpm.sock:", host: "www.###.com", referrer: "http://www.###.com/wp-cron.php?doing_wp_cron=1475416179.6478641033172607421875"
2016/10/02 09:49:39 [error] 6931#0: *469851 connect() to unix:///var/www/vhosts/system/###.com/php-fpm.sock failed (11: Resource temporarily unavailable) while connecting to upstream, client: 2601:81:4203:1bce:5809:b94c:4616:4730, server: ###.com, request: "POST /wp-admin/admin-ajax.php HTTP/1.1", upstream: "fastcgi://unix:///var/www/vhosts/system/###.com/php-fpm.sock:", host: "www.###.com", referrer: "http://www.###.com/###/"
2016/10/02 09:49:40 [error] 6931#0: *469853 connect() to unix:///var/www/vhosts/system/###.com/php-fpm.sock failed (11: Resource temporarily unavailable) while connecting to upstream, client: 2602:306:8b97:11a0:6843:ad77:251e:864a, server: ###.com, request: "GET /###/ HTTP/1.1", upstream: "fastcgi://unix:///var/www/vhosts/system/###.com/php-fpm.sock:", host: "www.###.com", referrer: "http://m.facebook.com/"

我有很多这些^

我现在将我的一些配置文件附加到我链接到的另一个线程中,所以你会对我服务器上的内容有所了解。

PHP-fpm.conf

include=/etc/php-fpm.d/*.conf

[global]
pid = /run/php-fpm/php-fpm.pid
error_log = /var/log/php-fpm/error.log
daemonize = no

/etc/php-fpm.d/www.conf

[www]

listen = 127.0.0.1:9000
listen.backlog = -1
listen.allowed_clients = 127.0.0.1
user = apache
group = apache
pm = dynamic
pm.max_children = 250
pm.start_servers = 20
pm.min_spare_servers = 20
pm.max_spare_servers = 35
pm.max_requests = 500
slowlog = /var/log/php-fpm/www-slow.log
php_admin_value[error_log] = /var/log/php-fpm/www-error.log
php_admin_flag[log_errors] = on
php_value[session.save_handler] = files
php_value[session.save_path] = /var/lib/php/session

/etc/php-fpm.d / ###。com.conf

[###.com]
prefix = /var/www/vhosts/system/$pool
user = ###
group = psacln

listen = php-fpm.sock
listen.owner = root
listen.group = psaserv
listen.mode = 0660

chdir = /

pm = ondemand
pm.max_children = 5
pm.process_idle_timeout = 10s
pm.start_servers = 1
pm.min_spare_servers = 1
pm.max_spare_servers = 1

catch_workers_output = yes

php_value[max_input_time] = 60
php_value[max_execution_time] = 60
php_value[memory_limit] = 128M
php_value[open_basedir] = none

sysctl.conf的

net.ipv6.conf.all.autoconf = 0
net.ipv6.conf.default.autoconf = 0
net.ipv6.conf.eth0.autoconf = 0
net.ipv6.conf.all.accept_ra = 0
net.ipv6.conf.default.accept_ra = 0
net.ipv6.conf.eth0.accept_ra = 0
net.core.somaxconn = 4096
net.ipv4.tcp_fin_timeout = 20
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_slow_start_after_idle = 0
net.ipv4.tcp_syncookies = 1

/etc/nginx/nginx.conf

worker_processes  1;

include /etc/nginx/modules.conf.d/*.conf;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    server_tokens off;
    include /etc/nginx/conf.d/*.conf;
}

# override global parameters e.g. worker_rlimit_nofile
include /etc/nginx/*global_params;

/etc/security/limits.conf 没有配置,只有评论。

这些是以下命令的结果:

ulimit -n
1024

ulimit -Sn
1024

ulimit -Hn
4096

cat /proc/sys/fs/file-max
3266168

free -m
              total        used        free      shared  buff/cache   available
Mem:          32089        1284        3784        1718       27020       28936
Swap:          1532           1        1531

关于 fastcgi_params - 我不知道在Plesk上哪里可以找到这个。我只能找到一个包含我不知道其值的变量的文件。 就像这些行一样(这就是整个文件的样子):

fastcgi_param  QUERY_STRING       $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;

如果遗漏了一些内容,我很抱歉,我真的试图让它尽可能详细,并且找到Plesk配置文件的位置也不容易。我不得不为上面附上的每个文件做一些研究......(这是我不喜欢Plesk说实话的原因之一,但这就是我的主题)

如果您需要我发送更多配置文件,请告知我们,我会在评论中附上。请告诉我在哪里可以找到它们(考虑到我使用的是Plesk v12.5)。 对我来说,根据我的需要和我的规格正确配置服务器并摆脱错误非常重要,所以请帮助我。 :)

谢谢!

2 个答案:

答案 0 :(得分:1)

尝试增加你的php-fpm孩子数,例如:

pm.max_children = 30
pm.start_servers = 10
pm.min_spare_servers = 3
pm.max_spare_servers = 15

然后突然的流量峰值不会产生错误

答案 1 :(得分:0)

我也遇到了这个问题。重新启动fpm修复了它

sudo service php7.1-fpm restart

更改php版本。