Converting to Nginx from Apache
Many people are have been talking about replacing Apache web servers with Nginx. Some of the advantages of Nginx are Faster, Smaller resource usage, and the ability to handle many more connections. From what I have seen so far, all this is true. But not much is mentioned about the surprises along the way. So here are a couple of things that may prepare you.
1: If you want to use php (who doesn’t?) you should use fastcgi. Seems simple enough, right? Well as long as you know that you need to use the spawn-fastcgi program that comes with lightttpd (another light weight web server) to launch php cgi processes… And are aware of some issues with the init script that is broken to the point that you cannot restart the processes without rewriting the script. it is simple. This took me some time to track down, and I came up with two primary answers. I chose to use this modified init for myself since I am already using gentoo there were no surprises. The other option that I saw was to patch php with sources found here. Since it is in Russian I chose to try this another day.
2: Rewrites are similar to Apache Rewrites, but just different enough to cause fits. For example my original Apache rewrite looked like this:
RewriteRule ^([^.]*[\w\d]+)$ ?entry=$1&%{QUERY_STRING} [NC]
Which became this in Nginx:
rewrite "^/([^.]*[\w\d]+)$" /?entry=$1&$query_string last;
In Apache the regular expression is matched without a / at the beginning, while in Nginx matches a request uri with a slash at the beginning. Also you have to enclose regular expressions with curly braces inside quotes. Also the fastcgi_params file contains the mappings of the fastcgi parameters to the variables.
Overall, once I got past these gotchas, Nginx is most everything that they claim and virtual servers are a breeze to set up compared to Apache.