将非www重定向到www(https)不起作用

时间:2017-11-25 03:52:34

标签: nginx

我正在尝试使用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";
    }


    }

1 个答案:

答案 0 :(得分:0)

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

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