How Nginx can make your Web application fast?
Nginx is considered as a better Web server than Apache HTTPD server. How can it help your Web application?
Why Nginx
Installation Memo
First of all, there are some dependence for Nginx:
- Nginx rewrite module requires PCRE library, Perl Compatible Regular Expressions: http://www.pcre.org
- Nginx ssl module depends on a SSL tookit, the popular one is OpenSSL. Make sure that the OpenSSL version is 0.9.8e or higher.
Basic commands:
$ sbin/nginx # start nginx server: both master processor and worker processor
$ sbin/nginx -h # help message, simple and easy to use
Basic Configuration
Nginx's main documentation wiki site: http://wiki.nginx.org/Main
rewrite condition and rewrite rule
Variables that we could use:
$host, $http_port
The core module defines many useful variables: http://wiki.nginx.org/HttpCoreModule
Timeout Settings
http://stackoverflow.com/questions/561946/how-do-i-prevent-a-gateway-timeout-with-nginx
We have the following directive for timeout setting:
fastcgi_send_timeout
fastcgi_read_timeout
send_timeout
client_header_timeout
client_body_timeout
Advance Rewrite Rules
some advanced Nginx rewrite rules:
User-Based (mod_userdir) Website Directories with Nginx: http://blog.sbf5.com/?p=6
Nginx, public_html, Part2 - PHP script: http://blog.sbf5.com/?p=16
Rewrite rules for wordpress: http://siava.su/2008/04/28/wordpress-mu-rewrite-rules-for-nginx/
It is a bit headache for first time Nginx user try to migrate some Apache HTTPD rewrite rules to Nginx rewrite rules. Here are some start up blog might help:
Migrate from Apache to Nginx: http://edwardawebb.com/site-news/migrate-apache-nginx-rewrites-intact
Nginx Doc Convert Rewrite Rules: http://nginx.org/en/docs/http/converting_rewrite_rules.html
SSL Support
The module httpd_ssl_module needs to be enabled for SSL support on Nginx.
ssl support on Nginx is quiet easy and strait forward: http://www.digicert.com/ssl-certificate-installation-nginx.htm
If you are using SSL and FastCGI together, you better turn on the HTTPS param for factcgi. I have experienced a redirect loop issue related to it. Check this for more details: http://sigttou.com/ssl-php-fastcgi-nginx.
fastcgi_param HTTPS on;
Gzip Support in Nginx
Gzip compression is supported by default in Nginx. However Nginx is a newer enough Web server that some of the older browser may not happy about gzip compression. Check this out: http://tumblelog.jauderho.com/post/27655495/gzip-compression-with-nginx.
So the gzip_disable option is used to disable gzip for some browser. The very useful one is to disable gzip for IE 6:
gzip_disable .MSIE [1-6].(?!.*SV1).;
Without this option, IE version 6 could not load some Nginx powered Web sites. It will hang up until you reloaded the page!
You also could trace how Nginx using gzip: http://stackoverflow.com/questions/2460821/how-can-i-check-that-the-nginx-gzip-static-module-is-working. It is using the strace.
Default Error Page
The error_page directive is used to set up default error (404, 500, etc) pages.