V
V
votanko2016-01-29 11:00:26
Nginx
votanko, 2016-01-29 11:00:26

Why do Wordpress + Nginx get 502/504 errors?

Hello.
There was a Wordpress site on an Nginx server.
For 5-6 months everything worked fine, a month ago 502 errors began to fly steadily
. There was such an error in the logs /var/log/error.log

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 googled and found the following advice
Advice
Restarted the server - everything worked, the next day an error 504 flew out
. The following was in the log.
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 this error, there were a couple of three of 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/"

I did not touch the nginx.conf configuration file.
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/; }

Asked on the Digitalocean forum and advised the following
put server_name after listen in defaults
change a value in /etc/php5/fpm/pool.d/www.conf so its request_terminate_timeout=30s
change a value in /etc/php5/fpm/php.ini so its max_execution_time = 30
Followed the advice, the server worked for 3 days without error.
Now error 504 crashes every 5 minutes approximately - I don’t understand what is the reason.
nginx/error.log
2016/01/29 02:43:01 [error] 3632#0: *3918 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 176.209.192.39, server: www.d2battle.club, request: "GET /favicon.ico HTTP/1.1", upstream: "fastcgi://127.0.0.1:7777", host: "d2battle.club", referrer: "http://d2battle.club/wp-admin/plugins.php?action=delete-selected&checked%5B0%5D=wp-super-edit%2Fwp-super-edit.php&plugin_status=all&paged=1&s&_wpnonce=852a3bede6"

/var/log/upstart/php5-fpm.log
[29-Jan-2016 02:53:25] WARNING: [pool www] child 3765 exited on signal 15 (SIGTERM) after 50.005905 seconds from start
[29-Jan-2016 02:53:25] NOTICE: [pool www] child 3768 started
[29-Jan-2016 02:54:25] WARNING: [pool www] child 3753, script '/home/webmaster/www/www.d2battle.club/xmlrpc.php' (request: "POST /xmlrpc.php") execution timed out (30.781351 sec), terminating
[29-Jan-2016 02:54:25] WARNING: [pool www] child 3753 exited on signal 15 (SIGTERM) after 480.050784 seconds from start
[29-Jan-2016 02:54:25] NOTICE: [pool www] child 3769 started
[29-Jan-2016 02:55:45] WARNING: [pool www] child 3762, script '/home/webmaster/www/www.d2battle.club/xmlrpc.php' (request: "POST /xmlrpc.php") execution timed out (34.839108 sec), terminating
[29-Jan-2016 02:55:45] WARNING: [pool www] child 3762 exited on signal 15 (SIGTERM) after 330.039058 seconds from start
[29-Jan-2016 02:55:45] NOTICE: [pool www] child 3770 started

I don't know what to do.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey Romanenko, 2016-01-29
@slimus

Enable php logging (+slowlog) and look for the error.

K
kazatchkoff, 2016-01-29
@kazatchkoff

Check the permissions on the /var/run/php5-fpm.sock socket file. The www-data user must have access to it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question