【问题标题】:how to redirect http://www to https://www - nginx如何将 http://www 重定向到 https://www - nginx
【发布时间】:2017-10-23 18:39:31
【问题描述】:

我要将http://www.example.com 重定向到https://www.example.com。在 nginx 服务器块中,我有以下 sn-p:

server {
listen 80;
server_name www.example.com example.com;
return 301 https://www.$host$request_uri;

}

如果example.com 正常工作并将http://example.com 重定向到https://www.example.com,但在http://www 中它不能正确重定向并将浏览器重定向到https://www.www.example.com。我该如何解决这个问题?

【问题讨论】:

    标签: redirect nginx https no-www


    【解决方案1】:

    使用$server_name 代替$host,例如:

    server {
        listen 80 default_server;
        listen [::]:80 default_server;
        server_name example.com www.example.com;
        return 301 https://$server_name$request_uri;
    }
    

    【讨论】:

      猜你喜欢
      • 2018-02-02
      • 2014-05-08
      • 1970-01-01
      • 2015-10-23
      • 2016-01-07
      • 2017-09-03
      • 2018-04-22
      • 1970-01-01
      • 2018-06-23
      相关资源
      最近更新 更多