What best practices do you use while using NGinx?
|
locked by Chris S♦ May 13 at 13:58
This question exists because it has historical significance, but it is not considered a good, on-topic question for this site, so please do not use it as evidence that you can ask similar questions here. This question and its answers are frozen and cannot be changed. More info: FAQ.
|
How to combine HTTP and HTTPS blocks.
This was posted as an answer to a different question. See here. |
|||
|
|
|
By far, the best tips I have ever seen are from the author on it's pitfall page: http://wiki.nginx.org/Pitfalls |
||||
|
|
|
Generally, using "if" is a bad practice (according to author of nginx). if possible, better to use try_file of error_page directives instead "if (-f ...)" Combining tip with maintenence.html file and tip with try_files we get:
location / {
try_files /maintenance.html $uri $uri/ @wordpress;
}
When maintenance ends, just mv maintenance.html from $root. |
|||||
|
|
Configure nginx to use stronger SSL ciphers. By default, SSLv2 is enabled (which you should disable if possible).
http://tumblelog.jauderho.com/post/121851623/nginx-and-stronger-ssl |
||||
|
|
|
Its often more efficient to use the
|
|||||
|
|
The
|
|||||||||||||
|
|
We set up Nginx with Chef, using this cookbook which contains scripts for handling nginx configuration similar to how Debian does Apache2, and also some sample templates with sane defaults. |
|||
|
|
|
Here's a good method for returning a maintenance page. All requests are rewritten and the correct http code is returned. (503 - Service unavailable)
|
|||||||
|
|
From nginx 0.7.12 and later, a "" is usable in server_name to catch requests without a "Host" header. You can use the following as a catchall for undefined virtual hosts.
|
|||||||||||
|
|
I also posted a while ago about how to properly handle gzip compression with nginx as older browsers may have issues with just a blanket gzip statement. HTH. http://tumblelog.jauderho.com/post/27655495/gzip-compression-with-nginx |
|||
|
|
|
I don't know if it is a best practice, but definitely a neat hack to get nested conditions in nginx. Here's a sample from the nginx wiki.
|
|||||
|
|
If you need to flip contextually between http and https for subdomains handled by the same server block, you can use variables to do so. Might not be the most efficient way to do things, but it works:
|
|||
|
|
|
I always try to use the The Pitfalls Page from the Nginx wiki has some great tips about best practices. |
||||
|
|
|
If you are using nginx as a proxy, having the timeout settings adjusted can be important to ensure you are not having nginx drop connections before your application is done with them, especially if you are dealing with a high traffic application:
|
||||
|
|
|
Did you take a look over here? |
|||
|
|