高流量的PHP-FPM,Nginx和错误502

时间:2018-07-17 08:23:44

标签: php nginx configuration configuration-management fpm

我目前面临一个大问题。当我遇到流量高峰(> 4000 Nginx并发连接)时,出现502错误(资源使用量不大)或站点变慢,我必须重新启动php7.0 fpm才能使所有功能再次正常运行。我不是Sysadmin(我正在尝试学习),我想知道什么是最佳配置。

我的硬件

Architecture:          x86_64
Hard disk              240 Go SSD
CPU op-mode(s):        32-bit, 64-bit
Memory:                110 Go DDR3-1333
Byte Order:            Little Endian
CPU(s):                24
On-line CPU(s) list:   0-23
Thread(s) per core:    2
Core(s) per socket:    6
Socket(s):             2
NUMA node(s):          2
Vendor ID:             GenuineIntel
CPU family:            6
Model:                 45
Model name:            Intel(R) Xeon(R) CPU E5-2620 0 @ 2.00GHz

我只放置配置的重要部分

PHP7.0-FPM配置

pm = static
pm.max_children = 500
pm.start_servers = 100
pm.min_spare_servers = 100
pm.max_spare_servers = 200
pm.process_idle_timeout = 1s;
pm.max_requests = 5000

Nginx配置

user www-data;
worker_processes 24;

pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
worker_rlimit_nofile 10240;

events {
        worker_connections 4096;
        use epoll;
        multi_accept on;
}

http {
    sendfile on;
    tcp_nopush on;
    server_tokens off;
    keepalive_timeout 65;
    reset_timedout_connection on;
    server_names_hash_bucket_size 256;
    client_max_body_size 32k;
    client_body_buffer_size 32k;
    client_body_in_single_buffer on;
    client_body_timeout 180s;
    client_header_timeout 180s;
    client_header_buffer_size 32k;
    large_client_header_buffers 4 32k;

站点Nginx配置

   location ~ \.php$ {
    include fastcgi_params;
    fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    fastcgi_index index.php;
    fastcgi_connect_timeout 180s;
    fastcgi_send_timeout 600s;
    fastcgi_read_timeout 600s;
    fastcgi_intercept_errors on;
    fastcgi_max_temp_file_size 0;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
 }

在此先感谢您的建议,如果您想了解更多详细信息,请随时告诉我。

0 个答案:

没有答案