From: W. Trevor King Date: Sun, 4 Mar 2012 15:59:23 +0000 (-0500) Subject: Add www.example.com -> example.com rewrite server to Nginx examples. X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=81c8617b725d16f16c676b1a80fdf6e35cbc4bfe;p=blog.git Add example.com -> example.com rewrite server to Nginx examples. --- diff --git a/posts/Nginx.mdwn b/posts/Nginx.mdwn index ebe37b0..36615fa 100644 --- a/posts/Nginx.mdwn +++ b/posts/Nginx.mdwn @@ -26,6 +26,22 @@ Now it's time to setup `/etc/nginx/nginx.conf`. Poking about online will give you lots of examples. Here are things that were useful to me, in the order they appear in the `http` block of my `nginx.conf`. +Redirecting `www.example.com` to `example.com` +============================================== + +This keeps people who accidentally add a `www.` prefix to your URL +from matching the wildcard virtual host block defined below. + + server { + # www.example.com -> example.com + listen 80; + listen 443 ssl; + server_name www.example.com; + ssl_certificate /etc/ssl/nginx/www.example.com.pem; + ssl_certificate_key /etc/ssl/nginx/www.example.com-key.pem; + rewrite ^/(.*)$ $scheme://example.com/$1 permanent; + } + Gitweb (and general CGI approach) =================================