<div dir="ltr">

<p class="MsoNormal">We are facing a strange issue on our servers. We have servers
with 1GB RAM and some drupal sites are running on it. </p>

<p class="MsoNormal"> </p>

<p class="MsoNormal">Generally all sites are loading fine but sometimes we are
unable to access any sites. After waiting for 10mts we are getting a 502 gateway
timeout error. In middle when we restart either nginx or php5-fpm it will load.</p>

<p class="MsoNormal"> </p>

<p class="MsoNormal">Our configurations are as follows:</p>

<p class="MsoNormal"> </p>

<p class="MsoNormal">/etc/nginx/nginx.conf:</p>

<p class="MsoNormal"> </p>

<p class="MsoNormal">user www-data;</p>

<p class="MsoNormal">worker_processes 1;</p>

<p class="MsoNormal">pid /run/nginx.pid;</p>

<p class="MsoNormal">worker_rlimit_nofile 400000;</p>

<p class="MsoNormal"> </p>

<p class="MsoNormal">events {</p>

<p class="MsoNormal"><span style>       
</span>worker_connections 10000;</p>

<p class="MsoNormal"><span style>        </span>multi_accept
on;</p>

<p class="MsoNormal"><span style>        </span>use epoll;</p>

<p class="MsoNormal">}</p>

<p class="MsoNormal"> </p>

<p class="MsoNormal">http {</p>

<p class="MsoNormal"> </p>

<p class="MsoNormal"><span style> </span><span style>       </span>access_log<span style>      </span>off;</p>

<p class="MsoNormal"><span style>        </span>sendfile on;</p>

<p class="MsoNormal"><span style>        </span>tcp_nopush on;</p>

<p class="MsoNormal"><span style>        </span>tcp_nodelay
on;</p>

<p class="MsoNormal"><span style>       
</span>keepalive_timeout 2;</p>

<p class="MsoNormal"><span style>       
</span>types_hash_max_size 2048;</p>

<p class="MsoNormal"><span style>        </span>server_tokens
off;</p>

<p class="MsoNormal"><span style>        </span>keepalive_requests
100000;</p>

<p class="MsoNormal"><span style>       
</span>reset_timedout_connection on;</p>

<p class="MsoNormal"><span style>       
</span>port_in_redirect off;</p>

<p class="MsoNormal"><span style>       
</span>client_max_body_size 10m;</p>

<p class="MsoNormal"><span style>       
</span>proxy_connect_timeout<span style>  </span>600s;</p>

<p class="MsoNormal"><span style>        </span>proxy_send_timeout<span style>  </span>600s;</p>

<p class="MsoNormal"><span style>        </span>proxy_read_timeout<span style>  </span>600s;</p>

<p class="MsoNormal"><span style>       </span><span style> </span>fastcgi_send_timeout 600s;</p>

<p class="MsoNormal"><span style>     </span><span style> </span><span style> </span>fastcgi_read_timeout
600s;</p>

<p class="MsoNormal"><span style>   </span><span style> </span><span style>  </span><span style> </span>open_file_cache max=200000 inactive=20s;</p>

<p class="MsoNormal"><span style>    </span><span style> </span><span style>  </span>open_file_cache_valid
30s;</p>

<p class="MsoNormal"><span style>    </span><span style> </span><span style> </span><span style> </span>open_file_cache_min_uses 2;</p>

<p class="MsoNormal"><span style>    </span><span style> </span><span style> </span><span style> </span>open_file_cache_errors on;</p>

<p class="MsoNormal"> </p>

<p class="MsoNormal">/etc/php5/fpm/pool.d/www.conf</p>

<p class="MsoNormal"> </p>

<p class="MsoNormal">pm.max_children = 5</p>

<p class="MsoNormal">pm.start_servers = 2</p>

<p class="MsoNormal">pm.min_spare_servers = 1</p>

<p class="MsoNormal">pm.max_spare_servers = 3</p>

<p class="MsoNormal">;pm.process_idle_timeout = 10s;</p>

<p class="MsoNormal">;pm.max_requests = 200</p>

<p class="MsoNormal">request_terminate_timeout = 300s</p>

<p class="MsoNormal"> </p>

<p class="MsoNormal">And please see the added contents in /etc/sysctl.conf</p>

<p class="MsoNormal"> </p>

<p class="MsoNormal">##########################</p>

<p class="MsoNormal">fs.file-max = 150000</p>

<p class="MsoNormal">net.core.netdev_max_backlog=32768</p>

<p class="MsoNormal">net.core.optmem_max=20480</p>

<p class="MsoNormal">#net.core.rmem_default=65536</p>

<p class="MsoNormal">#net.core.rmem_max=16777216</p>

<p class="MsoNormal">net.core.somaxconn=50000</p>

<p class="MsoNormal">#net.core.wmem_default=65536</p>

<p class="MsoNormal">#net.core.wmem_max=16777216</p>

<p class="MsoNormal">net.ipv4.tcp_fin_timeout=120</p>

<p class="MsoNormal">#net.ipv4.tcp_keepalive_intvl=30</p>

<p class="MsoNormal">#net.ipv4.tcp_keepalive_probes=3</p>

<p class="MsoNormal">#net.ipv4.tcp_keepalive_time=120</p>

<p class="MsoNormal">net.ipv4.tcp_max_orphans=262144</p>

<p class="MsoNormal">net.ipv4.tcp_max_syn_backlog=524288</p>

<p class="MsoNormal">net.ipv4.tcp_max_tw_buckets=524288</p>

<p class="MsoNormal">#net.ipv4.tcp_mem=1048576 1048576 2097152</p>

<p class="MsoNormal">#net.ipv4.tcp_no_metrics_save=1</p>

<p class="MsoNormal">net.ipv4.tcp_orphan_retries=0</p>

<p class="MsoNormal">#net.ipv4.tcp_rmem=4096 16384 16777216</p>

<p class="MsoNormal">#net.ipv4.tcp_synack_retries=2</p>

<p class="MsoNormal">net.ipv4.tcp_syncookies=1</p>

<p class="MsoNormal">#net.ipv4.tcp_syn_retries=2</p>

<p class="MsoNormal">#net.ipv4.tcp_wmem=4096 32768 16777216</p>

<p class="MsoNormal">##########################</p>

<p class="MsoNormal"> </p>

<p class="MsoNormal">Can anyone please help us on it.</p>

<p class="MsoNormal"> </p>

<p class="MsoNormal">Thanks</p>

<p class="MsoNormal"> </p>

Geo</div>