【问题标题】:Nginx Lets Encrypt Can't Redirect to wwwNginx 让加密无法重定向到 www
【发布时间】:2018-02-20 04:07:47
【问题描述】:

我的网站在带有 www 和非 www 的 https 访问中工作。我还将重定向从非 www 更改为 www,并且可以正常工作。所有访问都重定向到https://www.example.com

但是,即使使用相同的 nginx 默认配置,目前我的网站也无法重定向到 www。这里是

server {
    add_header X-Frame-Options SAMEORIGIN;
    listen 80 default_server;
    listen [::]:80 default_server;
    server_name example.com www.example.com;
    return 301 https://server_name$request_uri;}

server {
    listen 443 ssl default_server;
    listen [::]:443 ssl default_server;
    include snippets/ssl-example.com.conf;
    include snippets/ssl-params.conf;
    client_max_body_size 500M;

root /var/www/html/src/public;

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

    location / {
            try_files $uri $uri/ /index.php?$query_string;
    }

    location = /favicon.ico { log_not_found off; access_log off; }
    location = /robots.txt { log_not_found off; access_log off; allow all; }
    location ~* \.(css|gif|ico|jpeg|jpg|js|png)$ {
            expires max;
            log_not_found off;
    }

location ~ \.php$ {
            add_header X-Frame-Options SAMEORIGIN;
            try_files $uri =404;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_nam$
            include fastcgi_params;
    }

    location ~ /.well-known {
            allow all;
    }

    location ~ /\.ht {
            deny all;
        }

}

我正在使用 VPS debian 8.9 x64, nginx/1.6.2

【问题讨论】:

    标签: ssl redirect nginx web


    【解决方案1】:

    您可以尝试如下更新您的 http 服务器块吗?

    server {
        server_name example.com www.example.com;
        return 301 https://www.example.com$request_uri;
    }
    

    nginx 配置请参考https://stackoverflow.com/a/48811022/2196316...

    【讨论】:

      猜你喜欢
      • 2017-06-24
      • 1970-01-01
      • 2019-06-04
      • 2018-06-23
      • 2020-12-31
      • 2015-10-23
      相关资源
      最近更新 更多