Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Recently the website I maintain has been growing a lot and I saw the point coming where I'd want to switch from apache to nginx, because I kept on reading that it performs way better.

Now I've done the switch, and I have to say, nginx is keeping up just fine. However, php-fpm is forming a problem. Where the php pages used to take 0.1 second to generate with the same load they now take around 3 seconds!

Furthermore the error.log from nginx is being spammed with errors like:

upstream timed out (110: Connection timed out) while connecting to upstream, client: ...

I also tried using unix sockets instead, but those would complain about the following:

connect() to unix:/tmp/php5-fpm.sock failed (11: Resource temporarily unavailable) while connecting to upstream

I've fiddled with settings here and there but nothing seems to work. Changing the amount of pm.max_children doesn't seem to help a lot either, but with it's current amount at 350 it seems to be the lesser of all evil.

The server that's being used has 3 GB RAM (not all of it is free due to a MySQL server also running) along with 2 dual-core processors (4 cores in total).

Am I doing something majorly wrong with the settings here, or is the server simply not capable enough?

EDIT: Here is the nginx server block

server {
    listen   80;
    listen   [::]:80 default ipv6only=on;
    root /var/www;
    index index.php index.html index.htm;

     server_name localhost;

    location / {
            try_files $uri $uri/ /index.html;
    location /doc/ {
            alias /usr/share/doc/;
            autoindex on;
            deny all;
    location = /50x.html {
            root /usr/share/nginx/www;

    location ~ \.php$ {
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
            try_files $uri = 404;

            # With php5-cgi alone:
            # With php5-fpm:
            #fastcgi_pass unix:/tmp/php5-fpm.sock;
            fastcgi_index index.php;
            include fastcgi_params;
    location ~ /\.ht {
            deny all;

And the php-fpm pool:

user = www-data
group = www-data
listen =
;listen = /tmp/php5-fpm.sock
listen.backlog = -1

pm = dynamic
pm.max_children = 10 ;350
pm.start_servers = 4 ;200
pm.min_spare_servers = 2 ;10
pm.max_spare_servers = 6 ;350
pm.max_requests = 1536

rlimit_files = 65536
rlimit_core = unlimited

chdir = /
share|improve this question
How did you set it up? – Michael Hampton Jul 2 '13 at 17:53
Blindly switching doesn't do you any good if you don't know what you're doing... – ceejayoz Jul 2 '13 at 18:26
creeyoz: obviously, and that's why I did my fair part of research before switching. Not enough it seems though ;) @Michael Hampton: any specific settings you want to know? – lordstyx Jul 2 '13 at 18:37
You need at least your nginx server block and php-fpm pool configuration. – Michael Hampton Jul 2 '13 at 18:46
Potentially 550 php-fpm daemons with 350 children each - I am pretty sure your running out of RAM... Your configuration is completely oversized, please read the fpm documents to understand the options.. – pauska Jul 2 '13 at 22:34

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.