503 Errors with Nginx and PHP5-FPM

Posted on March 23, 2011

You may have noticed that DanConnor.com is now stupid fast. Well, a lot of that is due to Nginx and PHP5-FPM :D Nginx is pretty much my favorite thing ever.

I was encountering random 503 errors using php5-fpm and Nginx on my webserver after more or less following this guide. Some peeps suggested some extra fastcgi params that were supposed to mitigate the 503s, but they didn't help me. From what I could tell the 503 errors result when Nginx sends a request to php5-fpm but php5-fpm doesn't respond in time. For me this was happening due to my use of the dynamic thread-spin-up feature of php5-fpm's daemon: the threads were still being spun up as Nginx decided to time out the request.

Turns out I'm pretty sure the issue was a result of one of my attempts to harden the Nginx server: I set the keepalive_timeout option down to a fraction of the default, which is just too short for the dynamic threads to kick in. Upping this value has helped.

Hopefully other people can learn from my mistake.

comments powered by Disqus