PHP-FPM and Nginx: "Resource temporarily unavailable" errors in proxy_error_log
<p>I found the following discussion that was posted 4 years ago: <a href="https://stackoverflow.com/questions/8772015/502-gateway-errors-under-high-load-nginx-php-fpm">502 Gateway Errors under High Load (nginx/php-fpm)</a></p>

<p>Where someone had a similar issue as mine, but unfortunately I believe that the configurations he received were customized for his own server specs and I can't use the same configuration on my server. Anyway I would like to present the problem I have by myself and not to just tell you to go to the link I sent and read someone else's problem.</p>

<p>So to my own story - I have a big social media page where I post links to my website articles, which means that I have lots of traffic spikes during the day each time I share something. Recently I noticed that the site is too slow and sometimes not loading at all and unfortunately I am not very familiar in solving issues like this and I don't have a system administrator who manages my dedicated server to contact with since I rent it from OVH which offers unmanaged servers in low cost. The server has pretty good specs and this issue happens even when there are 100 active users on site. I can also see some errors in my server logs.</p>

<p>Server specs are the following:</p>

<p>AMD Opteron(tm) Processor 4334, AMD Opteron(tm) Processor 4334 (6 core(s))</p>

<p>SoftRaid 3x160GB SSD</p>

<p>32GB RAM</p>

<p>1Gbps connection</p>

<p>CentOS x64 Linux release 7.2.1511 (Core)</p>

<p>Plesk v12.5.30</p>

<hr>

<p>The errors I was talking about:</p>

<p><strong>proxy_error_log</strong></p>

<pre><code>2016/10/02 09:49:36 [error] 6931#0: *469804 connect() to unix:///var/www/vhosts/system/###.com/php-fpm.sock failed (11: Resource temporarily unavailable) while connecting to upstream, client: 2607:5300:60:5e68::, server: ###.com, request: "POST /wp-cron.php?doing_wp_cron=1475416176.6522459983825683593750 HTTP/1.1", upstream: "fastcgi://unix:///var/www/vhosts/system/###.com/php-fpm.sock:", host: "www.###.com", referrer: "http://www.###.com/wp-cron.php?doing_wp_cron=1475416176.6522459983825683593750"
2016/10/02 09:49:36 [error] 6931#0: *469806 connect() to unix:///var/www/vhosts/system/###.com/php-fpm.sock failed (11: Resource temporarily unavailable) while connecting to upstream, client: 2607:5300:60:5e68::, server: ###.com, request: "POST /wp-cron.php?doing_wp_cron=1475416176.8384990692138671875000 HTTP/1.1", upstream: "fastcgi://unix:///var/www/vhosts/system/###.com/php-fpm.sock:", host: "www.###.com", referrer: "http://www.###.com/wp-cron.php?doing_wp_cron=1475416176.8384990692138671875000"
2016/10/02 09:49:38 [error] 6931#0: *469826 connect() to unix:///var/www/vhosts/system/###.com/php-fpm.sock failed (11: Resource temporarily unavailable) while connecting to upstream, client: 73.77.251.156, server: ###.com, request: "GET /###/ HTTP/1.1", upstream: "fastcgi://unix:///var/www/vhosts/system/###.com/php-fpm.sock:", host: "www.###.com", referrer: "http://m.facebook.com/"
2016/10/02 09:49:38 [error] 6931#0: *469830 connect() to unix:///var/www/vhosts/system/###.com/php-fpm.sock failed (11: Resource temporarily unavailable) while connecting to upstream, client: 217.123.129.73, server: ###.com, request: "GET /###/ HTTP/1.1", upstream: "fastcgi://unix:///var/www/vhosts/system/###.com/php-fpm.sock:", host: "www.###.com", referrer: "http://m.facebook.com/"
2016/10/02 09:49:39 [error] 6931#0: *469840 connect() to unix:///var/www/vhosts/system/###.com/php-fpm.sock failed (11: Resource temporarily unavailable) while connecting to upstream, client: 2607:5300:60:5e68::, server: ###.com, request: "POST /wp-cron.php?doing_wp_cron=1475416179.1317949295043945312500 HTTP/1.1", upstream: "fastcgi://unix:///var/www/vhosts/system/###.com/php-fpm.sock:", host: "www.###.com", referrer: "http://www.###.com/wp-cron.php?doing_wp_cron=1475416179.1317949295043945312500"
2016/10/02 09:49:39 [error] 6931#0: *469842 connect() to unix:///var/www/vhosts/system/###.com/php-fpm.sock failed (11: Resource temporarily unavailable) while connecting to upstream, client: 2605:6001:f08a:3400:88d6:8b94:4499:8e36, server: ###.com, request: "GET /###/ HTTP/1.1", upstream: "fastcgi://unix:///var/www/vhosts/system/###.com/php-fpm.sock:", host: "www.###.com", referrer: "http://m.facebook.com/"
2016/10/02 09:49:39 [error] 6931#0: *469845 connect() to unix:///var/www/vhosts/system/###.com/php-fpm.sock failed (11: Resource temporarily unavailable) while connecting to upstream, client: 162.158.75.61, server: ###.com, request: "GET /###/ HTTP/1.1", upstream: "fastcgi://unix:///var/www/vhosts/system/###.com/php-fpm.sock:", host: "www.###.com", referrer: "http://m.facebook.com/"
2016/10/02 09:49:39 [error] 6931#0: *469847 connect() to unix:///var/www/vhosts/system/###.com/php-fpm.sock failed (11: Resource temporarily unavailable) while connecting to upstream, client: 2607:5300:60:5e68::, server: ###.com, request: "POST /wp-cron.php?doing_wp_cron=1475416179.6054229736328125000000 HTTP/1.1", upstream: "fastcgi://unix:///var/www/vhosts/system/###.com/php-fpm.sock:", host: "www.###.com", referrer: "http://www.###.com/wp-cron.php?doing_wp_cron=1475416179.6054229736328125000000"
2016/10/02 09:49:39 [error] 6931#0: *469849 connect() to unix:///var/www/vhosts/system/###.com/php-fpm.sock failed (11: Resource temporarily unavailable) while connecting to upstream, client: 2607:5300:60:5e68::, server: ###.com, request: "POST /wp-cron.php?doing_wp_cron=1475416179.6478641033172607421875 HTTP/1.1", upstream: "fastcgi://unix:///var/www/vhosts/system/###.com/php-fpm.sock:", host: "www.###.com", referrer: "http://www.###.com/wp-cron.php?doing_wp_cron=1475416179.6478641033172607421875"
2016/10/02 09:49:39 [error] 6931#0: *469851 connect() to unix:///var/www/vhosts/system/###.com/php-fpm.sock failed (11: Resource temporarily unavailable) while connecting to upstream, client: 2601:81:4203:1bce:5809:b94c:4616:4730, server: ###.com, request: "POST /wp-admin/admin-ajax.php HTTP/1.1", upstream: "fastcgi://unix:///var/www/vhosts/system/###.com/php-fpm.sock:", host: "www.###.com", referrer: "http://www.###.com/###/"
2016/10/02 09:49:40 [error] 6931#0: *469853 connect() to unix:///var/www/vhosts/system/###.com/php-fpm.sock failed (11: Resource temporarily unavailable) while connecting to upstream, client: 2602:306:8b97:11a0:6843:ad77:251e:864a, server: ###.com, request: "GET /###/ HTTP/1.1", upstream: "fastcgi://unix:///var/www/vhosts/system/###.com/php-fpm.sock:", host: "www.###.com", referrer: "http://m.facebook.com/"
</code></pre>

<p>I have tons of these ^</p>

<hr>

<p>I will now attach some of my configuration files as the guy in the other thread I linked to did, so you will have some sort of idea on what's going on my server.</p>

<p><strong>php-fpm.conf</strong></p>

<pre><code>include=/etc/php-fpm.d/*.conf

[global]
pid = /run/php-fpm/php-fpm.pid
error_log = /var/log/php-fpm/error.log
daemonize = no
</code></pre>

<hr>

<p><strong>/etc/php-fpm.d/www.conf</strong></p>

<pre><code>[www]

listen = 127.0.0.1:9000
listen.backlog = -1
listen.allowed_clients = 127.0.0.1
user = apache
group = apache
pm = dynamic
pm.max_children = 250
pm.start_servers = 20
pm.min_spare_servers = 20
pm.max_spare_servers = 35
pm.max_requests = 500
slowlog = /var/log/php-fpm/www-slow.log
php_admin_value[error_log] = /var/log/php-fpm/www-error.log
php_admin_flag[log_errors] = on
php_value[session.save_handler] = files
php_value[session.save_path] = /var/lib/php/session
</code></pre>

<hr>

<p><strong>/etc/php-fpm.d/###.com.conf</strong></p>

<pre><code>[###.com]
prefix = /var/www/vhosts/system/$pool
user = ###
group = psacln

listen = php-fpm.sock
listen.owner = root
listen.group = psaserv
listen.mode = 0660

chdir = /

pm = ondemand
pm.max_children = 5
pm.process_idle_timeout = 10s
pm.start_servers = 1
pm.min_spare_servers = 1
pm.max_spare_servers = 1

catch_workers_output = yes

php_value[max_input_time] = 60
php_value[max_execution_time] = 60
php_value[memory_limit] = 128M
php_value[open_basedir] = none
</code></pre>

<hr>

<p><strong>sysctl.conf</strong></p>

<pre><code>net.ipv6.conf.all.autoconf = 0
net.ipv6.conf.default.autoconf = 0
net.ipv6.conf.eth0.autoconf = 0
net.ipv6.conf.all.accept_ra = 0
net.ipv6.conf.default.accept_ra = 0
net.ipv6.conf.eth0.accept_ra = 0
net.core.somaxconn = 4096
net.ipv4.tcp_fin_timeout = 20
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_slow_start_after_idle = 0
net.ipv4.tcp_syncookies = 1
</code></pre>

<hr>

<p><strong>/etc/nginx/nginx.conf</strong></p>

<pre><code>worker_processes  1;

include /etc/nginx/modules.conf.d/*.conf;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    server_tokens off;
    include /etc/nginx/conf.d/*.conf;
}

# override global parameters e.g. worker_rlimit_nofile
include /etc/nginx/*global_params;
</code></pre>

<hr>

<p><strong>/etc/security/limits.conf</strong> has no configurations, only comments inside.</p>

<hr>

<p>These are the results for the following commands:</p>

<pre><code>ulimit -n
1024

ulimit -Sn
1024

ulimit -Hn
4096

cat /proc/sys/fs/file-max
3266168

free -m
              total        used        free      shared  buff/cache   available
Mem:          32089        1284        3784        1718       27020       28936
Swap:          1532           1        1531
</code></pre>

<hr>

<p>About <strong>fastcgi_params</strong> - I have no idea where to find this one on Plesk. I could only find a file with variables that I don't know their values.
Like these lines for example (that's how the whole file look like):</p>

<pre><code>fastcgi_param  QUERY_STRING       $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;
</code></pre>

<hr>

<p>I am sorry if there's something missing, I really tried to make it detailed as possible and it's also not easy to find where the configuration files are located with Plesk. I had to do some research for each file I attached above... (That's one of the reasons I don't like Plesk to be honest, but that's what I have atm)</p>

<p>If there are any more configuration files you need me to send, please let me know and I will attach it in the comments. Please also let me know where I can find them (considering that I'm using Plesk v12.5).
It's really important for me to configure the server properly for my needs and for my specs and get rid of the errors, so please help me. :)</p>

<p>Thank you!</p>