4

I have a very basic nginx setup that redirects www.example.com to example.com, following the best practice. It works, and in the Tor Firefox browser, going to http://www.idorecall.com/blog indeed updates the URL in the address bar to http://idorecall.com/blog.

But this doesn't change the URL in the address bar of Chrome, Firefox Portable, IE and Opera Portable.

Here's the modified default nginx config. There are no other nginx config files other than nginx.conf.

server {
  server_name www.idorecall.com;
  return 301 $scheme://idorecall.com$request_uri;
}

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

    root /var/www/html;

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

    server_name idorecall.com;

    location / {
        try_files $uri $uri/ =404;
    }

    location /blog {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header HOST $http_host;

        proxy_pass http://127.0.0.1:2368;
    }
}

wget -S, http://www.rexswain.com/httpview.html, browsershots etc. correctly detect the 301 "Moved permanently" redirect. Most browsers though preserve the www URL. Super frustrating. Firefox and Opera were installed from scratch, so there's no history hit of the www domain.

GitHub manages to redirect http(s)://www.github.com to https://github.com in every browser. How do they do this?

Michael Hampton
  • 237,123
  • 42
  • 477
  • 940
Dan Dascalescu
  • 590
  • 1
  • 9
  • 21
  • When i browse http://www.idorecall.com/blog with my Chrome brower i am redirected to http://bongo.idorecall.com/blog in the URL address bar... – krisFR May 10 '15 at 18:29
  • @krisFR - thank you! I've done that because I'm going nuts trying to figure out why even http://isup.me thinks that http://www.idorecall.com is up, when I had set it to redirect to that bogus hostname (now renamed `thisdoesntexist.idorecall.com`). – Dan Dascalescu May 10 '15 at 18:32
  • Where have you setup this redirect to this bogus hostname : `thisdoesntexist.idorecall.com` ? – krisFR May 10 '15 at 18:40
  • @krisFR: `return 301 $scheme://thisdoesntexist.idorecall.com$request_uri;`. – Dan Dascalescu May 10 '15 at 19:10

1 Answers1

4

You aren't seeing the redirect (and krisFR is) because you have IPv6 (and he does not), and your nginx server block containing the redirect is only being used for IPv4 connections.

When a server block omits the listen directive, it defaults to listen *:80, which listens only on all IPv4 addresses (and is equivalent to listen 80). Thus this server block will never be used for IPv6 connections, which fall through to your defined default_server.

To resolve the problem, add the appropriate listen directives to listen on both IPv4 and IPv6.

server {
  listen 80;
  listen [::]:80;
  server_name www.idorecall.com;
  return 301 $scheme://idorecall.com$request_uri;
}
Michael Hampton
  • 237,123
  • 42
  • 477
  • 940