From 81c8617b725d16f16c676b1a80fdf6e35cbc4bfe Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Sun, 4 Mar 2012 10:59:23 -0500 Subject: [PATCH] Add www.example.com -> example.com rewrite server to Nginx examples. --- posts/Nginx.mdwn | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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) ================================= -- 2.26.2