1

I am trying to move a PHP Laravel application from my development computer running apache to a server running nginx. I have configured the database connection, and my Laravel app (mostly) responds with the expected page. However, there are random times when the server does not respond quickly and returns a

504 Gateway Time-out

after some time. A

service php5-fpm restart

or trying again later fixes this temporarily. I am using nginx with PHP 5.6 (through FPM), HHVM, and MySQL. I do not want to increase the maximum execution time as the script should not take this long in first place.

I suspect this is an issue with either the PHP scripts in the new environment or a configuration issue. This should not be an issue with nginx itself, as static resources are sent correctly. How can I troubleshoot and fix this?

0

1 Answer 1

2
  • If you distrust the application, you can set a slow log in order to log each request that lasts more than N seconds (on fpm) by adding on your fpm pool configuration (default location tends to be (debian): /etc/php5/fpm/pool.d/www.conf)

    slowlog = /path/to/slow.log

    request_slowlog_timeout = Ns

change the N with amount of seconds you want, get it lower than the maximum execution time (so it will log before being timedout)

  • Take a look on the amount of children, max_requests and servers running with fpm. If it is a problem happening by time to time, maybe you are reaching the limit and no more connections are available for nginx.

  • Take a look on your nginx timeout values, maybe the fpm timeout is longer and nginx is giving up before getting the answer.

I think those hints may be helpful but I don't think I'm covering all the possible points to check, but those are a good start though

2
  • This was very helpful, thank you. I am still working on narrowing the problem down, but for now I increased the maximum number of child processes. Could you include the config file location /etc/php5/fpm/pool.d/www.conf in your answer for future users?
    – Streetlamp
    Aug 4, 2015 at 17:19
  • Thanks for the suggestion, added default file route for debian (the you commented) and added line break on code, it is lost when using bullets.
    – ignivs
    Aug 4, 2015 at 17:51

Not the answer you're looking for? Browse other questions tagged .