테스트 서버에서로드가 거의없는 Nginx + php-fpm“504 Gateway Time-out”오류


29

6 시간 동안 디버깅 한 후-이것을 포기하고 있습니다 : |

우리는 LAN에 nginx + php-fpm + mysql을 거의 100 개의 wordpress로 가지고 있습니다 (다른 디자이너 / 개발자가 모두 테스트 wordpres 설정을 작성하고 사용함)

우리는 오랫동안 아무런 문제없이 nginx를 사용하고 있습니다.

오늘 갑자기 nginx가 "504 Gateway Time-out"을 파란색으로 반환하기 시작했습니다.

가상 호스트의 nginx 오류 로그를 확인했습니다 ...

2010/09/06 21:24:24 [error] 12909#0: *349 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 192.168.0.1, server: rahul286.rtcamp.info, request: "GET /favicon.ico HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "rahul286.rtcamp.info"
2010/09/06 21:25:11 [error] 12909#0: *349 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 192.168.0.1, server: rahul286.rtcamp.info, request: "GET /favicon.ico HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "rahul286.rtcamp.info"
2010/09/06 21:25:11 [error] 12909#0: *443 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 192.168.0.1, server: rahul286.rtcamp.info, request: "GET /info.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "rahul286.rtcamp.info"
2010/09/06 21:25:12 [error] 12909#0: *443 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.0.1, server: rahul286.rtcamp.info, request: "GET /favicon.ico HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "rahul286.rtcamp.info"
2010/09/06 22:08:32 [error] 12909#0: *1025 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 192.168.0.1, server: rahul286.rtcamp.info, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "rahul286.rtcamp.info"
2010/09/06 22:09:33 [error] 12909#0: *1025 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 192.168.0.1, server: rahul286.rtcamp.info, request: "GET /favicon.ico HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "rahul286.rtcamp.info"
2010/09/06 22:09:40 [error] 12909#0: *1064 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 192.168.0.1, server: rahul286.rtcamp.info, request: "GET /info.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "rahul286.rtcamp.info"
2010/09/06 22:09:40 [error] 12909#0: *1064 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.0.1, server: rahul286.rtcamp.info, request: "GET /favicon.ico HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "rahul286.rtcamp.info"
2010/09/06 22:24:44 [error] 12909#0: *1313 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 192.168.0.1, server: rahul286.rtcamp.info, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "rahul286.rtcamp.info"
2010/09/06 22:24:53 [error] 12909#0: *1313 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 192.168.0.1, server: rahul286.rtcamp.info, request: "GET /favicon.ico HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "rahul286.rtcamp.info"

나는 TCP 모드를 통해 포트 9000에 PHP-FPM을 실행할 때, 내가 실행 "에서 netstat | 그렙 9000"특이한 ... 주목 뭔가를 (읽기의 용이성을 위해 여기에 부분적인 출력을 붙여 넣기)

tcp        9      0 localhost:9000          localhost:36094         CLOSE_WAIT  14269/php5-fpm  
tcp        0      0 localhost:46664         localhost:9000          FIN_WAIT2   -               
tcp     1257      0 localhost:9000          localhost:36135         CLOSE_WAIT  -               
tcp     1257      0 localhost:9000          localhost:36125         CLOSE_WAIT  -               
tcp        9      0 localhost:9000          localhost:36102         CLOSE_WAIT  14268/php5-fpm  
tcp        0      0 localhost:46662         localhost:9000          FIN_WAIT2   -               
tcp      745      0 localhost:9000          localhost:46644         CLOSE_WAIT  -               
tcp        0      0 localhost:46658         localhost:9000          FIN_WAIT2   -               
tcp     1265      0 localhost:9000          localhost:46607         CLOSE_WAIT  -               
tcp        0      0 localhost:46672         localhost:9000          ESTABLISHED 12909/nginx: worker
tcp     1257      0 localhost:9000          localhost:36119         CLOSE_WAIT  -               
tcp     1265      0 localhost:9000          localhost:46613         CLOSE_WAIT  -               
tcp        0      0 localhost:46646         localhost:9000          FIN_WAIT2   -               
tcp     1257      0 localhost:9000          localhost:36137         CLOSE_WAIT  -               
tcp        0      0 localhost:46670         localhost:9000          ESTABLISHED 12909/nginx: worker
tcp     1265      0 localhost:9000          localhost:46619         CLOSE_WAIT  -               
tcp     1336      0 localhost:9000          localhost:46668         ESTABLISHED -               
tcp        0      0 localhost:46648         localhost:9000          FIN_WAIT2   -               
tcp     1336      0 localhost:9000          localhost:46670         ESTABLISHED -               
tcp        9      0 localhost:9000          localhost:36108         CLOSE_WAIT  14274/php5-fpm  
tcp     1336      0 localhost:9000          localhost:46684         ESTABLISHED -               
tcp        0      0 localhost:46674         localhost:9000          ESTABLISHED 12909/nginx: worker
tcp     1336      0 localhost:9000          localhost:46666         ESTABLISHED -               
tcp     1257      0 localhost:9000          localhost:46648         CLOSE_WAIT  -               
tcp     1336      0 localhost:9000          localhost:46678         ESTABLISHED -               
tcp        0      0 localhost:46668         localhost:9000          ESTABLISHED 12909/nginx: wo             

아래에 강조 표시된 바와 같이 "CLOSE_WAIT"및 "FIN_WAIT2"쌍이 많이 있습니다 (위 출력에서).

tcp     1337      0 localhost:9000          localhost:46680         CLOSE_WAIT  -               
tcp        0      0 localhost:46680         localhost:9000          FIN_WAIT2   -

위의 포트 46680에 유의하십시오.

mysql 느린 쿼리 오류 로그를 활성화했지만 작동하지 않았습니다.

현재 cronjob (아래 명령 참조)을 통해 매분마다 php5-fpm을 다시 시작하면 모든 것이 "부드럽게"실행되지만 패치 작업이 싫어서 해결하고 싶습니다 ...

1 * * * * service php5-fpm restart > /dev/null

Google에서 광범위하게 검색했습니다. 도움이 없습니다. 언급 했듯이이 LAN의 테스트 서버, CPU로드는 0.10을 넘지 않으며 메모리 사용량도 25 % 미만입니다 (시스템에는 2GB RAM 및 우분투 서버가 설치되어 있음). 적어도 힌트를 버리십시오.

도움을 주셔서 감사합니다.

라훌

(참고-이것은 http://forum.nginx.org/read.php?11,127694를 다시 게시합니다 )

업데이트 : 아래 답변이 있습니다.

답변:


31

nginx 포럼에 대한 게시물에 대한 답변을 찾았습니다-http://forum.nginx.org/read.php? 2,127854

필자의 경우 대답은 다음과 같습니다.

request_terminate_timeout=30s

php-fpm 설정에서 (보통 /etc/php5/fpm/php-fpm.conf)

30 이외의 값도 사용할 수 있습니다.

기본 php.ini파일의 값과 일치하는 데 사용했습니다 .

max_execution_time = 30

모두 감사합니다. :-)


5
이 구성은 www.conf 파일에서도 찾을 수 있습니다. 그러나 답변 주셔서 감사합니다, 이것은 트릭을 한 것 같습니다.
— eddiemoya 2013 년

2
이것은 풀 레벨 지시어 [global]입니다. php-fpm.conf 섹션 에 넣으려고 할 때 오류 메시지가 나타납니다 . 풀 구성이있는 경우에만 작동합니다. 또한 request_terminate_timeout docs 입니다.
— tanius

이것이 내가 정말로 필요로하는 정답이라면 이번 주 금요일은 2015 년 최고입니다.
— Philip

2
나는 퍼팅 발견 request_terminate_timeout=30s내에 php-fpm.conf파일 것은 (111 연결 거부) 오류가 발생했습니다. www.conf파일 로 옮길 때 효과가있었습니다.
— AJB

php7을 사용할 때 CentOS 7.2에서 request_terminate_timeout은 다음 위치에 있습니다. /etc/php-fpm.d/www.conf
— nadavkav

16

다음은 내 문제를 해결 한 방법입니다.

http {섹션에서 /etc/nginx/nginx.conf를 다음과 같이 변경하십시오.

proxy_connect_timeout  600s;
proxy_send_timeout  600s;
proxy_read_timeout  600s;
fastcgi_send_timeout 600s;
fastcgi_read_timeout 600s;

그런 다음 nginx를 다시 시작하십시오.

/etc/init.d/nginx 재시작


2
예, 그것은 그 질문을하는 사람의 문제와 관련이없는 것처럼 보입니다.
— HopelessN00b

3
그러나 운 좋게도 그것은 내가 필요한 것입니다 :)
— luchaninov

이로 인해 문제가 해결되지는 않았지만 시간 초과 메시지 대신 실제 오류가 발생하여 실제 문제가 발생했습니다.
— Michael

4

PHP 5.3을 사용하는 경우 백 로그를 늘리십시오.

PHP 5.2를 사용하는 경우 패치를 백 포트하여 백 로그 크기를 128에서 늘리십시오.

또한 TCP 소켓 대신 유닉스 소켓을 사용하십시오. 유닉스 : /tmp/php5-cgi.sock (또는 관련 경로)


특히 유닉스 소켓 사용법에 동의해야합니다.
— Matt

답변 해 주셔서 감사합니다. nginx 메일 링리스트에서 해결책을 찾았습니다.
— rahul286

@ rahul286 어느 대답? 내가 관심!
— breiti

- @breiti 아래 제 답변을 참조 serverfault.com/a/179136/17440
— rahul286

3

감사합니다

request_terminate_timeout = 30s

그것은 나를 위해 완벽하게 작동합니다

그러나 "Worker Section"에있는 "/etc/php5/fpm/pool.d/www.conf"파일에이 줄을 삽입해야했습니다.

PHP 5.3.21-1-워드 프레스 3.5.1

http://php-fpm.org/wiki/Configuration_File


나는 당신의 레시피가 마술을 한 502 오류를 일으키는 요인들의 조합을 가졌습니다! 정말 감사합니다!
— Jorge Vicente Mendoza

2

필자의 경우 (같은 nginx 오류 메시지) 일부 문제가있는 PHP 스크립트가 실행을 끝내지 않고 무언가를 기다리지 않아 nginx에 대한 php5-fpm 자식이 더 이상 선택되지 않습니다.

고치다:

  1. 이 게시물에 언급 된 다른 실행 시간 제한을 추가하십시오. request_terminate_timeout=30s
  2. 자녀 수를 늘리십시오. 모든 것이 매력처럼 작동했습니다. pm.max_spare_servers=16 pm.min_spare_servers=2

이제 모든 것이 매력처럼 작동했습니다.


내 PHP 스크립트에서 외부 연결 요청이 오래 실행되었습니다. 오래 실행되는 작업을 찾아서 시간 초과하십시오.
— Ali Nadalizadeh '

1

나는 같은 문제가 있었고 Apache를 완전히 제거하여 해결했습니다.

yum remove httpd

그 후 PHP와 NGINX를 모두 다시 추천합니다.

/etc/init.d/nginx restart
/etc/init.d/php-fpm restart

1
당시 서버에는 아파치가 없었습니다. 향후 도움이 될 수 있으므로 귀하의 사례를 알게되어 기쁩니다.
— rahul286

0

나에게 rabbitmq를 서버에서 제거한 후에도 같은 문제가 발생했습니다. 위의 어느 것도 유용하지 않았으므로 모든 php5 모듈을 다시 설치하면 문제가 해결되었습니다. 그 서버에 데비안 8.2가있었습니다. 희망은 누군가에게 도움이 될 것입니다.


-1

이것은 또한 사람들을 도울 수 있습니다 :

설정에 따라 fastcgi 구성 매개 변수와 php ...를 봐야합니다 (제 경우에는 apache2 + php5-fpm을 사용하고 있습니다) .max_execution 시간은 fastcgi 모듈이 응답을 기다리는 시간에 달려 있습니다 ( 유휴 시간 초과) ...

http://www.fastcgi.com/mod_fastcgi/docs/mod_fastcgi.html#FastCgiExternalServer


왜 apache2를 사용합니까 ?? 나는 nginx를 직접 사용하여 php5-fpm과 상호 작용할 수 있음을 의미합니다. nginx가있을 때 Apache를 사용할 필요가 없습니다!
— rahul286

nginx를 사용하고 있다면 다른 사람들이 nginx를 사용하지 않으면 도움이 될 것입니다. :-) ...이 페이지에서 Apache2 + php5-fpm 관련 질문을 검색했습니다
— farinspace

승인. 나는 당신이 Nginx를 Apache와 함께 PHP 스크립트를 위해 과거에 사용한 포플과 같은 PHP 스크립트를 사용한다고 생각했습니다.
— rahul286
당사 사이트를 사용함과 동시에 당사의 쿠키 정책과 개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.