# I need the best nginx configuration please

**URL:** <https://www.ruby-forum.com/t/i-need-the-best-nginx-configuration-please/218624>\
**Category:** NGINX\
**Created:** [April 6, 2012, 3:48am UTC](https://www.ruby-forum.com/t/i-need-the-best-nginx-configuration-please/218624 "2012-04-06T03:48:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [April 6, 2012, 3:48am UTC](https://www.ruby-forum.com/t/i-need-the-best-nginx-configuration-please/218624/1 "2012-04-06T03:48:30Z")

</div>

Hello,

Please, I need the best nginx configuration for my servers  
My servers for images hosting  
In any server, From 2 to 5 million images  
The problem is that images do not appear quickly, a long time, Slow  
Please help me in this, I need the best nginx configuration

Thanks.

The configuration now

user nobody;

# no need for more workers in the proxy mode

worker\_processes 2;  
error\_log /var/log/nginx/error.log info;  
worker\_rlimit\_nofile 20480;  
events {  
worker\_connections 5120; # increase for busier servers  
use epoll; # you should use epoll here for Linux kernels 2.6.x  
}  
http {  
upload\_progress\_header id;  
upload\_progress uploads 5m;  
server\_name\_in\_redirect off;  
server\_names\_hash\_max\_size 10240;  
server\_names\_hash\_bucket\_size 1024;  
include mime.types;  
default\_type application/octet-stream;  
server\_tokens off;  
sendfile on;  
tcp\_nopush on;  
tcp\_nodelay on;  
keepalive\_timeout 5;  
gzip on;  
gzip\_vary on;  
gzip\_disable “MSIE [1-6].”;  
gzip\_proxied any;  
gzip\_http\_version 1.1;  
gzip\_min\_length 1000;  
gzip\_comp\_level 6;  
gzip\_buffers 16 8k;

# You can remove image/png image/x-icon image/gif image/jpeg if you have

slow CPU  
gzip\_types text/plain text/xml text/css application/x-javascript  
application/xml image/png image/x-icon image/gif image/jpeg  
application/xml+rss text/javascript application/atom+xml;  
ignore\_invalid\_headers on;  
client\_header\_timeout 360m;  
client\_body\_timeout 360m;  
send\_timeout 360m;  
reset\_timedout\_connection on;  
connection\_pool\_size 256;  
client\_header\_buffer\_size 256k;  
large\_client\_header\_buffers 4 256k;  
client\_max\_body\_size 2048M;  
client\_body\_buffer\_size 1024k;  
request\_pool\_size 32k;  
output\_buffers 4 32k;  
postpone\_output 1460;  
proxy\_temp\_path /home/matarNginx/nginx\_proxy/;  
client\_body\_in\_file\_only on;  
log\_format bytes\_log “$msec $bytes\_sent .”;  
include “/etc/nginx/vhosts/\*”;  
}

---

<div class="post-metadata">

**Author:** ![mohammed\_a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/bcef8e/32.png) [@mohammed\_a](https://www.ruby-forum.com/u/mohammed_a)\
**Post date:** [April 7, 2012, 5:51am UTC](https://www.ruby-forum.com/t/i-need-the-best-nginx-configuration-please/218624/2 "2012-04-07T05:51:49Z")

</div>

Hi there!

I guess, that your problem could be O.S. related and not Nginx related.  
I meant, probably, you are using more files per directory than your O.S.  
could support, in many cases, this limit is about 32.000 files per  
directory, but it may depends of your filesystem.  
take a look to the link below:

> <https://stackoverflow.com/questions/466521/how-many-files-can-i-put-in-a-directory>

In order to solve this issue, you must add a two or three directory  
levels  
structure. For example:

I guess your current directory structure is something like:  
/img/abcdefghijklmnopqrstuvwxyz.jpg

And you must try something like:  
/img/\*ab/cd/ef/\*abcdefghijklmnopqrstuvwxyz.jpg  
Or also works for somebody, to add a modulus function to the  
directories,  
for example:

/img/\*01/02/\*abcdefghijklmnopqrstuvwxyz.jpg

Hope it helps.

El 6 de abril de 2012 10:06, Volodymyr K.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)escribi:
