votanko
By:
votanko

Nginx Wordpress error 504

January 22, 2016 4.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: 74.217.28.153, server:   www.d2battle.club, request: "POST /xmlrpc.php HTTP/1.0", upstream: 
 "fastcgi://unix:/var/run/php5-fpm.sock:", host: "188.166.31.15"

I found the following advice:
Solution
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: 66.249.66.148, server: www.d2battle.club, request:  
 "GET /done_battles/11/ HTTP/1.1", upstream: "fastcgi://127.0.0.1:7777", host: "d2battle.club  

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: 176.209.206.24, server: www.d2battle.club, request: "GET /favicon.ico HTTP/1.1",  
 upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "d2battle.club", referrer: "http://d2battle.club/"  

nginx.conf:

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

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: http://jvdc.me/fix-502-bad-gateway-error-on-nginx-server-after-upgrading-php/

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.
    http://stackoverflow.com/questions/10470109/error-502-in-nginx-php5-fpm/10470827#10470827
    Just another port 127.0.0.1:7777.
    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 www.d2battle.club 
        server {
          server_name www.d2battle.club;
          listen 80;
        
          root /home/webmaster/www/www.d2battle.club;
          index index.php index.html;
          location / {
            try_files $uri $uri/ /index.php?$args;
          }
        
          location ~ .php$ {
            try_files $uri /index.php;
            include fastcgi_params;
            fastcgi_pass 127.0.0.1:7777;
            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 (http://jvdc.me/fix-502-bad-gateway-error-on-nginx-server-after-upgrading-php/) worked for me like a charm.

Have another answer? Share your knowledge.