【问题标题】:Redirect non-www to www (https) not working将非 www 重定向到 www (https) 不起作用
【发布时间】:2017-11-25 03:52:34
【问题描述】:

我正在尝试使用 nginx 配置文件将所有 http 和 http 调用重定向到 https://www.example.com。

问题是重定向不适用于http://example.com ->https://www.example.com

所有其他人都工作。

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

server {
listen 443;
ssl on;
    ssl_certificate /root/www.example.com.crt;
    ssl_certificate_key /root/example.com.key;

        server_name www.example.com;
    add_header Strict-Transport-Security "max-age=31536000";
        access_log   /var/log/nginx/example.com.access.log;
        error_log    /var/log/nginx/example.com.error.log;

        root /var/www/example.com/htdocs;
        index index.php index.html;

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

        location ~ .php$ {
                include fastcgi_params;
                fastcgi_pass 127.0.0.1:9000;
        }

    location ~* \.(?:ico|css|js|gif|jpe?g|png)$ {
    expires 30d;
    add_header Pragma public;
    add_header Cache-Control "public";
    }


    }

【问题讨论】:

  • 那么会发生什么?

标签: nginx


【解决方案1】:

你可以试试这些,我猜它是关于使用确切的陈述

https://www.rosehosting.com/blog/how-to-redirect-http-traffic-to-https-in-nginx-and-apache/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-01-11
    • 2018-10-24
    • 2016-09-09
    • 1970-01-01
    • 2023-04-02
    • 1970-01-01
    • 1970-01-01
    • 2018-04-22
    相关资源
    最近更新 更多