Nginx 502�������������������ܽ�
һЩ������Nginx�ϵ���վ��ʱ��������“502 Bad Gateway”��������Щʱ������Ƶ���ij��֡������Ǵ�Google�Ѽ�������һЩNginx 502�������Ų鷽�������ο���
Nginx 502������ԭ���Ƚ϶࣬����Ϊ�ڴ���ģʽ�º��˷������������������ġ���Щ����һ�㶼����nginx���������⣬һ��Ҫ�Ӻ�����ԭ��nginx����Щ�����������Լ������ˣ���ʵ��nginx���ƹ��߱������ɣ��Ͼ������������⣬bad gateway��������bad nginx�����ò��˽����˿�������ֱ�Ӱ���������nginx���ϣ�ϣ��nginx��һ���汾���ѳ�����ʾд���Ѻ�һЩ�����ٲ��������ڼ�һ�� 502 Bad Gateway��������������Լ��Ĵ�����
Nginx 502�Ĵ�������
502������ͨ���ij����������Ǻ���������������upstream����������ôһ�����ã�proxy_next_upstream����������ָ���� nginx�ڴ�һ����������ȡ�����������ִ���ʱ��ת����һ��������������ͷд�ϵľ��ǻ�����502��������������Ĭ����error timeout��error���ǵ���������֮���ģ�timeout���Ƕ�ȡ������ʱ���Ƚ��������⡣��һ����ȫд�ϵģ�
proxy_next_upstream error timeout invalid_header http_500 http_503;
�������ڿ�����Ҫȥ��http_500��һ���ˣ�http_500ָ�����˷���500����ʱ��תһ�����������˵�jsp�����Ļ�����������ӡһ�� stacktrace�Ĵ�����Ϣ�����ڱ�502ȡ���ˡ�����˾�ij���Ա�ɲ���ô��Ϊ�������϶���nginx�����˴�������ʵ��û�ո����ǽ���502��ԭ�� ��……
503�����Ϳ��Ա�������Ϊ����ͨ����apache resin������apache��������error����resin������������503�����Ի����б�Ҫ�����ġ�
�����취
����502���⣬�������ȿ��ǰ���������������ȥ������
1���鿴��ǰ��PHP FastCGI�������Ƿ����ã�
netstat -anpo | grep "php-cgi" | wc -l
����ʵ��ʹ�õ�“FastCGI������”�ӽ�Ԥ����“FastCGI������”����ô��˵��“FastCGI������”�����ã���Ҫ������
2������PHP������ִ��ʱ�䳬����Nginx�ĵȴ�ʱ�䣬�����ʵ�����nginx.conf�����ļ���FastCGI��timeoutʱ�䣬���磺
...... http { ...... fastcgi_connect_timeout 300; fastcgi_send_timeout 300; fastcgi_read_timeout 300; ...... } ......
php.ini��memory_limit�����˻�����������php.ini��memory_limitΪ64M������nginx�����ֺ��ˣ�ԭ����PHP���ڴ治���ˡ�
�����������˻������������⣬���Բο�������Щ������
һ��max-children��max-requests
һ̨��������������nginx php(fpm) xcache���������վ� 300W pv����
�������������������������� phpҳ��������cpuʹ����ͻȻ�����ܵͣ�ϵͳ����ͻȻ�����ܸߣ��鿴������������Ҳ�ᷢ��ͻȻ�����˺ܵ͡���������ֻ���������Ӿͻָ���
����php-fpm����־�ļ�������һЩ����
Sep 30 08:32:23.289973 [NOTICE] fpm_unix_init_main(), line 271: getrlimit(nofile): max:51200, cur:51200 Sep 30 08:32:23.290212 [NOTICE] fpm_sockets_init_main(), line 371: using inherited socket fd=10, “127.0.0.1:9000″ Sep 30 08:32:23.290342 [NOTICE] fpm_event_init_main(), line 109: libevent: using epoll Sep 30 08:32:23.296426 [NOTICE] fpm_init(), line 47: fpm is running, pid 30587
���⼸����ǰ�棬��1000���еĹر�children�Ϳ���children����־
ԭ����php-fpm��һ������ max_requests���ò���ָ���ˣ�ÿ��children���ദ�����ٸ����������ᱻ�رգ�Ĭ�ϵ�������500����Ϊphp�ǰ�������ѯ��ÿ�� children���ڴ������£�ÿ��childre����max_requests���õ�ʱ�䶼��࣬�������������е�children��������ͬһʱ�� ���رա�
�����ڼ䣬nginx����php�ļ�ת����php-fpm����������cpu�ή���ܵ�(���ô���php��������ִ��sql)�������ػ������ܸ�(�رպͿ���children��nginx�ȴ�php-fpm)����������Ҳ�����ܵ�(nginx���������ݴ������ͻ���)
���������ܼ�����children�����������ҽ� max_requests ����δ 0 ����һ���Ƚϴ���ֵ��
���� /usr/local/php/etc/php-fpm.conf
����������������(���ݷ�����ʵ������������Ҳ���У�
<value name=”max_children”>5120</value> <value name=”max_requests”>600</value>
Ȼ������php-fpm��
�������ӻ�����������С
��nginx��error log������“pstream sent too big header while reading response header from upstream”�����Ĵ�����ʾ��������һ�����ϣ�������nginx��������һ��bug���ɵ�,������վ��ҳ������ռ�û��������ܹ��ο�����д���� �İ취�����˻�����������С���ã�502���⳹����������ϵͳ����Ա�ֶԲ������˵���ֻ������2�����ò�����client head buffer��fastcgi buffer size��
����request_terminate_timeout
������Ҫ����һЩpost�������ݿ�������ʱ������502�����������������ھ�̬ҳ�������г�������ô���Բ鿴һ��php-fpm.conf�����е�һ�
request_terminate_timeout
����ֵ��max_execution_time������fast-cgi��ִ�нű�ʱ�䡣
0s
0sΪ�رգ���������ִ����ȥ������ʱװ��ʱ��û��ϸ������һ�����֣�
���֣����������ˣ�ִ�кܳ�ʱ��Ҳ���������ˡ�
�Ż�fastcgi�У������Ըĸ�����ֵ5s ����Ч����
php-cgi�����������á�phpִ��ʱ�䳤��������php-cgi������������������502������
- ת����ע����Դ��ITѧϰ�� ��ַ��http://www.t086.com/ �����������Ƽ�������
- �ر������� ��վ�������ر�������ֹת�ص�ר�������������¿�������ת�أ���������ע��������ԭʼ���ߡ����°�Ȩ������ԭʼ�������С����ڱ���վת�����µĸ��˺���վ�����DZ�ʾ������л�⡣������վת�ص������а�Ȩ��������ϵ���ǣ����ǻᾡ�����Ը�����
- ������������������̸�����ɶ��ر�
- ��������������ѡʳƷ����2020�ļ��ȵ�Ͷ�ʲ��Ժ���������
- �����ڵ�����֤50���ƴ�50����ָ֤�������Ĺ���
- ����֤50����Щ��Ʊ_��֤50Ȩ����������
- ������300����֤50����֤500��ָ��2019���ڶ��ζ��ڵ���������
- ������300��ֵ/�ɳ�ָ�����Ʒ����������й�ƽ��Ȩ���½�
- ����ָ֤��������֤50��ָ��������
- ����ָ֤��������֤����ָ��������
- ����ָ֤��������֤100ָ��������
- ����ָ֤����������300ָ��������