我有一个非常基本的nginx设置,将www.example.comredirect到example.com ,遵循最佳实践 。 它的工作原理,并在Tor火狐浏览器,去http://www.idorecall.com/blog确实更新地址栏中的urlhttp://idorecall.com/blog 。
但这并不会改变Chrome,Firefox Portable,IE和Opera Portable的地址栏中的url。
这是修改后的default nginxconfiguration。 除nginx.conf之外,没有其他的nginxconfiguration文件。
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等正确检测301“永久移动”redirect。 大多数浏览器虽然保留www的URL。 超级沮丧。 Firefox和Opera是从头开始安装的,所以没有任何www域的历史命中。
GitHub设法在每个浏览器中将http(s)://www.github.comredirect到https://github.com 。 他们如何做到这一点?
你没有看到redirect(和krisFR是),因为你有IPv6(而他没有),你的包含redirect的nginx server块只用于IPv4连接。
当server块省略listen指令时 ,它默认listen *:80 ,它只监听所有的IPv4地址(相当于listen 80 )。 因此,这个server块将永远不会用于IPv6连接,这个连接将通过您定义的default_server 。
要解决此问题,请添加适当的listen指令以侦听IPv4和IPv6。
server { listen 80; listen [::]:80; server_name www.idorecall.com; return 301 $scheme://idorecall.com$request_uri; }