I want www.lizardgizzards.com to redirect to https://lizardgizzards.com

But instead it redirects to https://www.lizardgizzards.com

Here's my redirect config:

server {
        listen 80;
        listen [::]:80;

        server_name lizardgizzards.com www.lizardgizzards.com;

        if ($host = 'www.lizardgizzards.com') {
                return 301 https://lizardgizzards.com;

        if ($host = 'lizardgizzards.com') {
                return 301 https://$host$request_uri;

my SSL config:

server {
        root /var/www/html/lizardgizzards.com;

        index index.html index.htm index.nginx-debian.html;

        server_name lizardgizzards.com;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ =404;

        listen [::]:443 ssl ipv6only=on default_server; # managed by Certbot
        listen 443 ssl default_server; # managed by Certbot
        ssl_certificate /etc/letsencrypt/live/lizardgizzards.com/fullchain.pem; # managed by Certbot
        ssl_certificate_key /etc/letsencrypt/live/lizardgizzards.com/privkey.pem; # managed by Certbot
        include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
        ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

It seems to be working with the dig command:

ubuntu@mars:/var/www/html$ curl -I www.lizardgizzards.com
HTTP/1.1 301 Moved Permanently
Server: nginx/1.14.0 (Ubuntu)
Date: Thu, 09 May 2019 03:52:45 GMT
Content-Type: text/html
Content-Length: 194
Connection: keep-alive
Location: http://lizardgizzards.com

But my browser doesn't seem to get the memo. Even in an incognito window it goes to the wrong URL: https://www.lizardgizzards.com


So the problem was that I had previously accepted a security exception in Chrome for an invalid certificate...

In Chrome I opted to re-enable SSL warnings and now the redirect is working properly.

  • you don't have any redirects configured in your ssl configuration. – Gerald Schneider May 9 at 6:53

Check your browsers network tab in the developer bar (in Chrome or Firefox press [F12], in Safari use [ALT][CMD][i] and change to network). Activate "Preserve log" and "Disable cache" for better results.

Start browsing your desired URL again and watch the things your browser is doing.

I assume that you will see a redirect 307 from your http to your https location. This means, that your browser will use an internal redirect. Instead of accessing the server and handling the server's response, your browser has an internal list of sites supporting the https protocol. Instead of using http it will redirect requests of these sites internally to https.

Such sites have sent the HSTS header to inform browsers about the preference of using https. This header is sent with a validity in seconds. Actually its pretty hard to remove this preference from browsers once sent.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.