All of my sites are now running Nginx rather than Apache, which has several major advantages. Apache uses a separate process for each connection, so if you have a very busy site with lots of simultaneous connections it can use a huge amount of memory. Nginx, on the other hand, uses one worker process with a fixed number of CGI processes no matter how many connections it’s serving.
As you can see from my resource chart, the memory usage dropped dramatically when I switched over to Nginx.
Nginx has a few drawbacks, however. It doesn’t support Subversion or WebDAV, so I first had to move my Subversion repositories off my virtual private server. I ended up moving them to ProjectLocker. Most importantly, Nginx doesn’t use a .htaccess file. Instead, it uses its own configuration files, which DreamHost documents here.
Basically you need to create a nginx folder in your home directory, and make a subdirectory for each domain, for example ~/nginx/mcdevzone.com, and create a configuration file, which can be named anything. The syntax is different than .htaccess, although it has many of the same capabilities such as access control or rewriting URLs.
For a WordPress site, all you need is this:
####################### # Permalinks if (!-e $request_filename) { rewrite ^.*$ /index.php last; }
DreamHost provides many more examples on their Wiki page, and you can find even more at the official Nginx site.
One important rule you should add to your config file, which DreamHost leaves out, is this one which will prevent users from viewing your .htaccess file, if you still have one.
location ~ /\.ht { deny all; }
I ran into a few gotchas, but once I figured them out I was able to get everything running smoothly. According to DreamHost’s documentation, the site-wide Nginx configuration file is at /dh/nginx/servers/httpd-psXXXXXX/nginx.conf, but I found that it didn’t exist, at least on my server. Instead it was named nginx.conf.pushing, so as a result Nginx refused to start. Once I renamed it, I was able to start nginx. You WILL need to have an admin user on your private server in order to access that file and restart nginx.
UPDATE: The problem I ran into with the missing config file was because the update didn’t finish properly for some reason.
DreamHost’s older virtual private servers don’t support Nginx, so if you want to use it, you may have to request to have your PS moved to a newer system.
If you have a very busy site, Nginx can help you deal with the load, so it’s worth checking out. Several major sites including WordPress.com, Hulu, and Github are using Nginx, so it’s definitely production quality.
> Apache uses a separate process for each connection, so if you have a
> very busy site with lots of simultaneous connections it can use a huge amount of memory.
I am sorry but your are wrong. Apache supports 3 different approach in handling requests: prefork mode (as you said), multiple threads and event-driven (like nginx)
> Nginx, on the other hand, uses one worker process with a fixed number of CGI processes
> no matter how many connections it’s serving.
Nope, you can configure nginx to have more than one worker process
That applies to the default configurations. Almost every web host I've used has Apache in the prefork mode, and in most cases they don't let you change it.