简体   繁体   中英

Nginx / PHP-FPM 504 Gateway Timeout

I am using php-fpm with nginx. I have scripts which take an uploaded excel sheet and process it. This is a long running job. However, after 60 seconds of execution time I get a 504 Gateway Timeout error.

The php script keeps running to completion. So nothing is stopping the script from completing.

I need to stop this error.

I have been playing with the fastcgi_read_timeout parameter. However it doesn't seem to fix this problem. However I know it's taking this parameter into consideration because if I change it to 0 and restart nginx, then the 504 gateway timeout shows straight away.

location ~ \.php$ {
      try_files $uri =404;
      include /etc/nginx/fastcgi_params;
      fastcgi_pass unix:/var/run/php-fpm/www.sock;
      fastcgi_read_timeout 300;
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
      fastcgi_param PHP_VALUE "upload_max_filesize = 190M \n post_max_size=190M \n max_execution_time = 300";
   }

Any help would be appreciated as I have hit a roadblock in terms of resolving this issue.

I almost completely gave up on this! However at the last minute I came up with the answer.

The servers are on Amazon AWS behind a load balancer. The load balancer had the idle-timeout attribute set at 60 seconds. Changing this setting fixed the problem!!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM