I recently made the transition from running my web server on Apache to running it on Nginx. Well, I made the switch at the start of the summer, but only now is my Nginx configuration stable. One of the biggest obstacles I encountered trying to get Nginx to do what I want was a lack of documentation. The official documentation is anemic and I found examples hard to come by. So now I'd like to share parts of my nginx.conf file that cover some common use cases that I found frustrating to implement.
I would like all of the URLs for ericw.ca to be without the "www." prefix. Indeed, that is their canonical form. This configuration snippet uses the 301 Moved Permanently status to redirect users arriving at "www.ericw.ca" to "ericw.ca".
server { server_name www.ericw.ca; rewrite ^(.*) http://ericw.ca$1 permanent; } server { server_name ericw.ca; # The rest of the configuration... }
You can see this in action if you go to www.ericw.ca.
Aareet 15 Aug 09
Google webmaster tools lets you manage your search results so the results also only show the canonical URL. Interesting snippet - I finally managed to get nginx up on my box (yup, the laptop) to play around with before I migrate to hosting from wordpress and it's absolute hell. Do you know other places I can get reading material on nginx?
Eric 15 Aug 09
Unfortunately, not really. The official documentation seems to be the only comprehensive guide to setting up Nginx. For specific problems I used Google and waded through mailing lists. The ru.sysoev.nginx tends to have lots of useful discussion. Igor, the author of Nginx, posts there so the answers also tend to be authoritative.