Monday 28 November 2011

php5-fpm and nginx config to avoid Internal server errors

This is a setting that I've found pretty stable (on a high-end server with 16GB ram) for a busy Drupal site, after a lot of headackes with 503 Error due to poor configuration:

nano /etc/php5/fpm/pool.d/www.conf

pm = dynamic

pm.max_children = 25
pm.min_spare_servers = 2
pm.max_spare_servers = 10

pm.max_requests = 100
 request_terminate_timeout = 30s



This may be also have been useful to put the following line in php.ini to make sure that we get rid of faulty long processes:

max_execution_time = 30

Impose the same time limit in the nginx  fastcgi directives:

nano /etc/nginx/sites-available/default:
            fastcgi_connect_timeout 30;

            fastcgi_send_timeout 30;

            fastcgi_read_timeout 30;

And finally, in /etc/php5/fpm/php.in, my memory limit is:


memory_limit = 256M


Don't forget to restart both nginx and php5-fpm for the changes to take effect.



No comments:

Post a Comment