Since I started hosting a website on the server, I get 505's, 504's, timeouts on it, as well as for the other websites hosted on that same server (but these other websites have no issues).
The server's OS is Ubuntu16.04 and it has php7.0-fpm nginx, apparently misconfigured.
How to avoid all other websites to suffer from the newly hosted website's timeouts? Or how to avoid these timeouts at all (without fixing the php errors as I have nothing to do with that)?
The php code has many errors. php7.0-fpm logs reveal a timeout.
/var/log/php7.0-fpm.log
[26-Mar-2018 20:29:54] WARNING: [pool www] child 17012, script '/var/www/xxxxxx.com/index.php' (request: "POST /index.php?function=my-profile") execution timed out (306.572078 sec), terminating [26-Mar-2018 20:29:54] WARNING: [pool www] child 17012 exited on signal 15 (SIGTERM) after 1100.011016 seconds from start [26-Mar-2018 20:29:54] NOTICE: [pool www] child 19559 started
/var/log/nginx/error.log
Nginx reveals so many php warnings that I'm not quite sure where to look at.
/etc/nginx/nginx.conf
http {
# ...
fastcgi_buffers 8 16k;
fastcgi_buffer_size 32k;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
# ...
}
/etc/php/7.0/fpm/pool.d
pm = dynamic
pm.start_servers = 4
pm.min_spare_servers = 2
pm.max_spare_servers = 6
pm.process_idle_timeout = 10s
pm.max_requests = 500
/etc/php/7.0/fpm
default_socket_timeout = 60
max_execution_time = 300
max_input_time = 60
memory_limit = 128M
The server block includes this part /etc/nginx/global/wordpress.conf
# Deny access to any files with a .php extension in the uploads directory
# Works in sub-directory installs and also in multisite network
# Keep logging the requests to parse later (or to pass to firewall utilities such as fail2ban)
location ~* /(?:uploads|files)/.*\.php$ {
deny all;
}
# Directives to send expires headers and turn off 404 error logging for Static assets
location ~* ^.+\.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpe?g|gif|png|ico|zip|pdf|t?gz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|swf|bmp|txt|rtf|md)$ {
access_log off;
log_not_found off;
expires max;
# CORS headers; this is wide-open, you want to tight it up a bit
add_header Cache-Control public;
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Methods GET,OPTIONS;
add_header Access-Control-Allow-Headers *;
}
# Attempted to match last if rules below fail.
location / {
try_files $uri $uri/ /index.php?$args;
}
# Add trailing slash to */wp-admin requests.
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
# Pass PHP scripts to PHP-FPM daemon
# Check: http://wiki.nginx.org/Pitfalls
location ~* \.php$ {
# filter out problem conditions
try_files $uri $uri/ =404;
# bring in parameters
include fastcgi.conf;
# send requests to upstream
# fastcgi_pass phpfpm;
# fastcgi_pass 127.0.0.1:9000;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_read_timeout 300;
}