nginx + php5-fpm 中的错误 502 [英] Error 502 in nginx + php5-fpm

查看:30
本文介绍了nginx + php5-fpm 中的错误 502的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 subj 有一些错误.服务器不高负载:~15% CPU,有几 Gb 内存,硬盘不忙.但是大约有 3% 的情况会抛出错误 502.

I have some error with subj. Server doesn't high loaded: ~15% CPU, there are several Gb of memory, HDD is not buisy. But error 502 throws approximately in 3% of cases.

程序:Debian 6、nginx/0.7.62、php5-fpm (5.3.3-1).

Programs: Debian 6, nginx/0.7.62, php5-fpm (5.3.3-1).

在nginx的error.log中是这个错误:

In error.log of nginx is this error:

connect() to unix:/var/run/php5-fpm.sock failed

php5-fpm 的状态通常是这样的:

State of php5-fpm usually like this:

accepted conn:   41680
pool:             www
process manager:  dynamic
idle processes:   258
active processes: 1
total processes:  259

我认为,这意味着负载不高.

I think, this mean loading is not high.

我增加了 backlog 参数:在 sysctl - net.core.somaxconn = 5000,在 php-fpm pool - listen.backlog = 5000.没有效果.

I have increased backlog params: in sysctl - net.core.somaxconn = 5000, in php-fpm pool - listen.backlog = 5000. No effect.

我引用一个配置:

/etc/nginx/nginx.conf

user www-data;
worker_processes  8;
timer_resolution 100ms;
worker_rlimit_nofile 20240;
worker_priority -5;

error_log  /var/log/nginx/error.log;
pid        /var/run/nginx.pid;

events {
    worker_connections  2048;
    use epoll;
    # multi_accept on;
}

http {
    include       /etc/nginx/mime.types;

    access_log  /var/log/nginx/access.log;

    sendfile        on;
    tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;
    tcp_nodelay        on;

    gzip  on;
    gzip_min_length 1100;
    gzip_buffers 64 8k;
    gzip_comp_level 3;
    gzip_http_version 1.1;
    gzip_proxied any;
    gzip_types text/plain application/xml application/x-javascript text/css;
    gzip_disable "MSIE [1-6].(?!.*SV1)";

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;

    client_max_body_size 100M;
    server_tokens off;
}

/etc/nginx/php_location

fastcgi_pass   unix:/var/run/php5-fpm.sock;
fastcgi_index  index.php;
fastcgi_param  SCRIPT_FILENAME  $document_root/$fastcgi_script_name;
fastcgi_buffers 256 128k;
#fastcgi_buffer_size 16k;
#fastcgi_busy_buffers_size 256k;
fastcgi_connect_timeout 300s;
fastcgi_send_timeout 300s;
fastcgi_read_timeout 300s;
include fastcgi_params;

php-fpm 池

[www]
listen = /var/run/php5-fpm.sock
listen.backlog = 5000
listen.owner = www-data
listen.group = www-data
listen.mode = 0666
user = www-data
group = www-data
pm = dynamic
pm.max_children = 1024
pm.start_servers = 64
pm.min_spare_servers = 64
pm.max_spare_servers = 128
pm.max_requests = 32000
pm.status_path = /system/php5-fpm-status
slowlog = /var/www/log/php-fpm.log.slow
chdir = /var/www

我可以做些什么来优化这个系统并使其使用所有服务器资源?

What can I do to optimize this system and make this use all server resources?

附注.对不起,我的英语不好.

PS. I'm sorry, my english is bad.

推荐答案

问题在于套接字本身,它在高负载情况下的问题是众所周知的.请考虑使用 TCPIP 连接而不是 unix socket,为此您需要进行以下更改:

The issue is socket itself, its problems on high-load cases is well-known. Please consider using TCPIP connection instead of unix socket, for that you need to make these changes:

  • php-fpm 池配置中将listen =/var/run/php5-fpm.sock 替换为listen = 127.0.0.1:7777>
  • /etc/nginx/php_location中将fastcgi_pass unix:/var/run/php5-fpm.sock;替换为fastcgi_pass 127.0.0.1:7777;
  • in php-fpm pool configuration replace listen = /var/run/php5-fpm.sock with listen = 127.0.0.1:7777
  • in /etc/nginx/php_location replace fastcgi_pass unix:/var/run/php5-fpm.sock; with fastcgi_pass 127.0.0.1:7777;

这篇关于nginx + php5-fpm 中的错误 502的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆