Access Logs
By default nginx will write every request to a file on disk for logging purposes. If you don’t use access logs for anything you can simply just turn it off and avoid the disk writes.
access_log off;
Gzip
Gzip compress content before it is delivered to the client. It’s a simple and effective way to speed up your site.
gzip on; gzip_comp_level 2; gzip_min_length 1000; gzip_proxied expired no-cache no-store private auth; gzip_types text/plain application/xml; gzip_disable "MSIE [1-6]\.";
Caching static files
80% of the end-user response time is spent on the front-end. Most of this time is tied up in downloading all the components in the page: images, stylesheets, scripts, Flash, etc. Reducing the number of components in turn reduces the number of HTTP requests required to render the page. Example, i’m using the following configuration to cache static files on nginx
location ~* "\.(js|ico|gif|jpg|png|css|html|htm|swf|htc|xml|bmp|cur)$" { root /home/site/public_html; add_header Pragma "public"; add_header Cache-Control "public"; expires 3M; access_log off; log_not_found off; }
KeepAlive
KeepAlive allows multiple requests to be sent over the same TCP/IP connection. Turning it on can greatly improve the speed of your server, particularly when you have static pages and are serving quite a bit of images from your server. An example would be a catalogue site with screenshots. From my experience it is best to keep it On.
keepalive_timeout in nginx has default is very high. I recommend change it to 10-20.
keepalive_timeout 15
Make best nginx configuration
To make best nginx configuration, you should visit to http://wiki.nginx.org/Pitfalls
Pages: 1 2
{ 5 comments… read them below or add one }
Also do not forget to fine tune the tcp_* parameters of nginx.
Hey, great article. I enabled the gzip compression on mine and it made a huge difference.
Question though: My server uses nginx as a reverse proxy, it talkes to apache. In this type of a setup, do you know a way to cache static files, like in your configuration:
[code]
location ~* “\.(js|ico|gif|jpg|png|css|html|htm|swf|htc|xml|bmp|cur)$” {
root /home/site/public_html;
add_header Pragma “public”;
add_header Cache-Control “public”;
expires 3M;
access_log off;
log_not_found off;
}
[/code]
Once again, great article, thanks!
I do not even know how I ended up here, but I thought this post was good.
I don’t know who you are but certainly you’re going to a famous blogger if you are
not already 😉 Cheers!
I do accept as true with all the concepts you have offered in your post.
They’re really convincing and will definitely work. Still, the posts are very short for novices. May just you please extend them a bit from subsequent time? Thanks for the post.
Pretty! This was an incredibly wonderful post.
Thanks for providing these details.