Add www.example.com -> example.com rewrite server to Nginx examples.
authorW. Trevor King <wking@drexel.edu>
Sun, 4 Mar 2012 15:59:23 +0000 (10:59 -0500)
committerW. Trevor King <wking@drexel.edu>
Sun, 4 Mar 2012 15:59:23 +0000 (10:59 -0500)
posts/Nginx.mdwn

index ebe37b09048af051eb0a338928fb82f82d8ebad6..36615fa4497c882dd54e29d119b38f500f119916 100644 (file)
@@ -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)
 =================================