开启 HSTS 后,如何让顶级域名 https 跳转 www?

2017-08-12 09:45:15 +08:00
 roustar31

前端:Nginx,开启了 HTTPS。配置如下: server { listen 80; listen 443 ssl http2; ssl_certificate /usr/local/nginx/conf/ssl/www.test.com.crt; ssl_certificate_key /usr/local/nginx/conf/ssl/www.test.com.key; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers EECDH+CHACHA20:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5; ssl_prefer_server_ciphers on; ssl_session_timeout 10m; ssl_session_cache builtin:1000 shared:SSL:10m; ssl_buffer_size 1400; add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload"; ssl_stapling on; ssl_stapling_verify on; server_name www.test.com test.com; access_log off; index index.html index.htm index.php; root /data/wwwroot/www.test.com; if ($ssl_protocol = "") { return 301 https://$host$request_uri; } if ($host != www.test.com) { return 301 $scheme://www.test.com$request_uri; } include /usr/local/nginx/conf/rewrite/discuz.conf; location ~ [^/].php(/|$) { #fastcgi_pass remote_php_ip:9000; fastcgi_pass unix:/dev/shm/php-cgi.sock; fastcgi_index index.php; include fastcgi.conf; } location ~ ..(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$ { expires 30d; access_log off; } location ~ ..(js|css)?$ { expires 7d; access_log off; } location ~ /.ht { deny all; } }

现在的问题是: 浏览器输入 test.com 可以直接转到 https://www.test.com ;输入 https://test.com 提示无法连接( ERR_CONNECTION_REFUSED ) 去谷歌的那个 HSTS 站点提交也提交不了。 请问有什么可行的解决方案?

4099 次点击
所在节点    问与答
24 条回复
matsuz
2017-08-12 19:05:17 +08:00
server 段加个 if 判断,如果域名不是 www 就 301 跳转
DJason
2017-08-13 02:38:23 +08:00
你说的是这样的吗 aitbx.com
roustar31
2017-08-15 08:27:09 +08:00
@DJason 不是
roustar31
2017-08-15 08:44:02 +08:00
@Kilerd 有五毛钱的关系

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/382361

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX