2

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?

  • When i browse idorecall.com/blog with my Chrome brower i am redirected to 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 isup.me thinks that 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
3

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;
}
  • This did the trick! BTW, was there some indication that I have IPv6, or an educated guess based on the fact that Tor nodes and krisFR got the redirect while I didn't? – Dan Dascalescu May 10 '15 at 19:09
  • @DanDascalescu Yes, I simply tried it both ways. – Michael Hampton May 10 '15 at 19:10
  • Didn't have ipv6 to test both ;) – krisFR May 10 '15 at 19:13
  • @krisFR I've had IPv6 since 2006. What's taking you so long? :) – Michael Hampton May 10 '15 at 19:14
  • @Michael Hampton Have it at work, not at home right now where i am for the week-end ;) – krisFR May 10 '15 at 19:16

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.