# Nginx Tuning

**URL:** <https://www.ruby-forum.com/t/nginx-tuning/244130>\
**Category:** NGINX\
**Created:** [February 24, 2016, 4:42pm UTC](https://www.ruby-forum.com/t/nginx-tuning/244130 "2016-02-24T16:42:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rafa\_F](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/958977/32.png) [@Rafa\_F](https://www.ruby-forum.com/u/Rafa_F)\
**Post date:** [February 24, 2016, 4:42pm UTC](https://www.ruby-forum.com/t/nginx-tuning/244130/1 "2016-02-24T16:42:01Z")

</div>

Alright here is the situtation. I have nginx and with passenger  
running. I  
can send load to the server and after a certain point I just start  
getting  
500’s back. I have not been able to see what is causing it. I have  
made  
tweaks to the config based on some blog posts but I can’t get past a  
certain  
point. I get to about 1400 requests per minute and than start seeing  
500s.  
The configs are below. It almost seems like I might be hitting an OS or  
server limit that I can’t seem to find. The server is a 8CPU, 8GB  
cloud  
server.

nginx.conf

user www-data;  
worker\_processes 8;  
worker\_rlimit\_nofile 30000;

error\_log /var/log/nginx/error.log debug;  
pid /var/run/nginx.pid;

events {  
worker\_connections 3500;  
use epoll;  
}

http {

log\_format main  
‘$status:$request\_time:$upstream\_response\_time:$pipe:$body\_bytes\_sent  
$connection $  
remote\_addr $host $remote\_user [$time\_local] “$request” “$http\_referer”  
“$http\_user\_agent” “$http\_x\_f  
orwarded\_for” $upstream\_addr $upstream\_cache\_status “in: $http\_cookie”’  
include /etc/nginx/mime.types;  
default\_type application/octet-stream;

access\_log /var/log/nginx/access.log;

sendfile on;  
tcp\_nopush on;  
tcp\_nodelay on;

keepalive\_requests 100;  
keepalive\_timeout 65;

gzip on;  
gzip\_http\_version 1.0;  
gzip\_comp\_level 2;  
gzip\_proxied any;  
gzip\_vary off;  
gzip\_types text/plain text/css application/x-javascript text/xml  
application/xml application/rss+xm  
l application/atom+xml text/javascript application/javascript  
application/json text/mathml;  
gzip\_min\_length 1000;  
gzip\_disable “MSIE [1-6].”;

variables\_hash\_max\_size 1024;  
variables\_hash\_bucket\_size 64;  
server\_names\_hash\_bucket\_size 64;  
types\_hash\_max\_size 2048;  
types\_hash\_bucket\_size 64;

include /etc/nginx/conf.d/_.conf;  
include /etc/nginx/sites-enabled/_;  
}

site.conf

server {  
listen 0.0.0.0:80;  
location ~ ^/api/.\* {  
include /etc/nginx/conf.d/include/restrict.include;  
}

## redirect http to https

location ~ .\* {  
return 301 https://$host$request\_uri;  
}  
}

server {  
listen 0.0.0.0:443;  
server\_name [somesite.net](http://somesite.net);

## set client body size to 15M, to address file upload limitations

client\_max\_body\_size 15M;

include /etc/nginx/conf.d/actual\_config/\*.include;

ssl on;  
ssl\_certificate /etc/nginx/self\_signed;  
ssl\_certificate\_key /etc/nginx/cert.key;

# Display the maintenance page if it exists

if (-f $document\_root/system/maintenance.html){  
rewrite ^(.\*)$ /system/maintenance.html last;  
break;  
}

# If the file exists as a static file serve it directly without

# running all the other rewite tests on it

if (-f $request\_filename) {  
break;  
}

# this is the meat of the rails page caching config

# it adds .html to the end of the url and then checks

# the filesystem for that file. If it exists, then we

# rewite the url to have explicit .html on the end

# and then send it on its way to the next config rule.

# if there is no file on the fs then it sets all the

# necessary headers and proxies to our upstream mongrels

if (-f $request\_filename.html) {  
rewrite (.\*) $1.html break;  
}

# Use any statically compressed javascript or stylesheet files

location ~\* ^/(javascripts|stylesheets)/.\*.(js|css) {  
#gzip\_static on;  
}  
}

passenger.conf

passenger\_root  
/opt/ruby/lib/ruby/gems/2.2.0/gems/passenger-enterprise-server-5.0.24;  
passenger\_ruby /opt/ruby/bin/ruby;  
passenger\_max\_pool\_size 31;  
passenger\_min\_instances 31;  
passenger\_pre\_start [https://llocalhost](https://llocalhost);  
passenger\_log\_level 2;

site.conf

location / {  
passenger\_enabled on;  
rails\_env lt;

access\_log /var/log/nginx/access.log;  
error\_log /var/log/nginx/error.log debug;

passenger\_base\_uri /;  
alias /home/sites/site/current/public/$1;  
passenger\_app\_root /home/sites/site/current;  
index index.html index.htm;  
}

#Asset displaying.  
location ~ ^/(assets)/ {  
gzip\_static on;  
expires max;  
add\_header Cache-Control public;  
root /home/sites/site/current/public;  
}

Posted at Nginx Forum:

> **[Nginx Tuning.](https://forum.nginx.org/read.php?2,264775,264775#msg-264775)**
>
> Alright here is the situtation. I have nginx and with passenger running. I can send load to the server and after a certain point I just start getting 500's back. I have not been able to see what is causing it. I have made tweaks to the config based...

---

<div class="post-metadata">

**Author:** ![rodrigda](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ea666f/32.png) [@rodrigda](https://www.ruby-forum.com/u/rodrigda)\
**Post date:** [February 24, 2016, 6:02pm UTC](https://www.ruby-forum.com/t/nginx-tuning/244130/2 "2016-02-24T18:02:39Z")

</div>

You should check the nginx error log as it may have vital clues to  
resolve  
this.

---

<div class="post-metadata">

**Author:** ![rodrigda](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ea666f/32.png) [@rodrigda](https://www.ruby-forum.com/u/rodrigda)\
**Post date:** [February 24, 2016, 6:06pm UTC](https://www.ruby-forum.com/t/nginx-tuning/244130/3 "2016-02-24T18:06:10Z")

</div>

I just keep seeing things like this.

2016/02/24 17:04:56 [info] 5989#0: \*108120 client 127.0.0.1 closed  
keepalive  
connection

When I get the 500 that is all I get. The location of the call that was  
getting made and a 500.

Posted at Nginx Forum:

> **[Re: Nginx Tuning.](https://forum.nginx.org/read.php?2,264775,264782#msg-264782)**
>
> Alright here is the situtation. I have nginx and with passenger running. I can send load to the server and after a certain point I just start getting 500's back. I have not been able to see what is causing it. I have made tweaks to the config based...
