Nginx Wordpress error 504

January 22, 2016 8.7k views
Nginx WordPress Ubuntu

There was a site on Wordpress worked for about 5 months without any complaints.
Recently I started to consistently produce an error 502. In this error logs:

2016/01/18 03:58:54 [error] 13245#0: *125039 connect()  
 to unix:/var/run/php5-fpm.sock failed (11: Resource temporarily unavailable) while connecting to upstream,  
 client:, server:, request: "POST /xmlrpc.php HTTP/1.0", upstream: 
 "fastcgi://unix:/var/run/php5-fpm.sock:", host: ""

I found the following advice:
I restart the server - everything worked, the next day there was a 504 error.
The log was as follows:

2016/01/19 02:37:38 [error] 3677#0: *5484 upstream timed out (110: Connection timed out)  
 while reading response header from upstream, client:, server:, request:  
 "GET /done_battles/11/ HTTP/1.1", upstream: "fastcgi://", host: "  

Before the error was a pair of triple the following messages:

2016/01/18 04:43:23 [crit] 13245#0: *125168 connect() to unix:/var/run/php5-fpm.sock failed (2: No such file or directory)  
 while connecting to upstream, client:, server:, request: "GET /favicon.ico HTTP/1.1",  
 upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "", referrer: ""  


user www-data; worker_processes 4; pid /run/;

events { worker_connections 768; # multi_accept on; }

http {

sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 2048; # server_tokens off;

# server_names_hash_bucket_size 64; # server_name_in_redirect off;

include /etc/nginx/mime.types; default_type application/octet-stream;

## # Logging Settings ##

access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log;

## # Gzip Settings ##

gzip on; gzip_disable "msie6";

# gzip_vary on; # gzip_proxied any; # gzip_comp_level 6; # gzip_buffers 16 8k; # gzip_http_version 1.1; # gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

## # nginx-naxsi config ## # Uncomment it if you installed nginx-naxsi ##

#include /etc/nginx/naxsi_core.rules;

## # nginx-passenger config ## # Uncomment it if you installed nginx-passenger ## #passenger_root /usr; #passenger_ruby /usr/bin/ruby;

## # Virtual Host Configs ##

include /etc/nginx/conf.d/.conf; include /etc/nginx/sites-enabled/; }

I am so sorry for my bad english.

2 Answers

Not sure if you googled, but try solution 2a from this link:

Still a learner my self but it seems your nginx can't find the /var/run/php5-fpm.sock location.
Try the fix from the guide and let me know how it goes ^^

  • I made this.
    Just another port
    before - error 502.
    after - error 504.
    Now the server drops every 10-20 minutes.

    • Can you please how me your /etc/sites-available/default ?
      Maybe some of the config in there is not optimized for WordPress

      • Maybe, but server worked well for about 5 months

        etc/nginx/sites-available# cat 
        server {
          listen 80;
          root /home/webmaster/www/;
          index index.php index.html;
          location / {
            try_files $uri $uri/ /index.php?$args;
          location ~ .php$ {
            try_files $uri /index.php;
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_index index.php;
          1. put server_name after listen in defaults
          2. change a value in /etc/php5/fpm/pool.d/www.conf so its request_terminate_timeout=30s
          3. change a value in /etc/php5/fpm/php.ini so its max_execution_time = 30

          See if it helps ^^

  • Thank you so much for your help!

Just wanted to chime in here. I also had a similar problem (tried to update wordpress, site went down; nginx log pushed out a fastcgi upstream read error related to headers).

Had tried rebooting php5-fpm, nginx, and server with no luck.

The 2b. fix listed at the site above ( worked for me like a charm.

Have another answer? Share your knowledge.