Nginx redirect www to non www domain
January 25, 2012
I've been playing around with Nginx web server over the past few days, its a great light weight web server, ideal for VPS's or smaller Amazon EC2 instances where resources are not as abundant.
One thing I like about nginx so far is the configuration, while I haven't had to do anything overly complex with it yet, it does seam to be quite flexible.
Here's a quick example of redirecting a www domain to the non www version:
server {
listen 80;
server_name www.example.com;
rewrite ^ http://example.com/ permanent;
}
Note that's just one way of doing it, by creating a new virtual server for the non-www hostname and redirecting all requests. You can also do this from within your main server declaration, eg:
server {
listen 80
root /web/root/;
if ($host != 'example.com') {
rewrite ^ http://example.com/ permanent;
}
}
I like the first method better, but this just goes to show how flexible the configuration is for nginx
Tweet
Trackbacks
Trackback Address: 802/B9084252B20A962F4A7BDD94BB043352
Comments
On 01/26/2012 at 6:36:24 AM EST VBart wrote:
1
server { listen 80; server_name www.example.com; return 301 http://example.com/; }
On 01/26/2012 at 12:52:44 PM EST Pete Freitag wrote:
2
@VBart - very nice example thanks for posting.
On 02/27/2012 at 10:11:15 PM EST Antoinette wrote:
3
That cuesas a race condition between the tail view process which is trying to read the file and the server process that is writing to the same file thanks for including this explanation.. the problem was baffling to me
On 03/27/2012 at 9:57:35 AM EDT hey wrote:
4
nice site yes
Post a Comment
Recent Entries
- Writing Secure CFML cfObjective 2013 Slides
- Upgrading to Java 7 on Linux
- J2EE Sessions in CF10 Uses Secure Cookies
- Learn about ColdFusion Security at cfObjective 2013
- Session Loss and Session Fixation in ColdFusion
- FuseGuard 2.3 Released
- CKEditor Spell Checker Plugin
- Adobe Says Go Ahead and Upgrade your ColdFusion JVM


add to del.icio.us


