0

我想将域的所有流量重定向到一个目标: https ://example.com 我们想将 http 更改为 https,将 www 更改为 nonwww。

Nginx 1.8.1 是服务器

这是虚拟主机:

server {
listen xxx.xxx.xxx.xxx:80;
listen xxx.xxx.xxx.xxx:443 ssl;

ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_certificate /www/clients/client1/web2/ssl/example.com.crt;
ssl_certificate_key /www/clients/client1/web2/ssl/example.com.key;

server_name example.com www.example.com;

root   /var/www/example.com/web;
#This is a rewrite from www.example.com  -> example.com
if ($http_host = "www.example.com") {
rewrite ^ $scheme://example.com$request_uri? permanent;
} 

......
......
}                        

我们遇到的问题是,我们检查的每个重定向和重写规则都适用于这三种情况:

https://example.com    -->     is right target        works
http://www.example.com -->     https://example.com  works
http://example.com     -->     https://example.com  works

https://**www**.example.com  ---> https://example.com  don't works 

在浏览器中,我们看到https://www.example.com而不是目标 SSL 域https://example.com

在这种情况下,我们的 SL 证书显示“不受信任” - 消息

vhost 的配置由 ISPConfig 预设。

有没有人有同样的经历?也许是一个解决方案。

4

2 回答 2

0

这是我对我的域所做的事情。

server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;
    return 301 https://$host$request_uri$is_args$args;
    root /var/www/public_html;
    index index.php index.html index.htm;

    server_name domain.com www.domain.com;
    add_header  Strict-Transport-Security "max-age=31536000";


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

    location ~ \.php$ {
            try_files $uri =404;
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_index index.php;
            include fastcgi_params;
        }

    location ~*  \.(jpg|jpeg|png|gif|ico|css|js|svg)$ {
            expires 2d;
    }   
}

server {
    listen 443;
    add_header Strict-Transport-Security "max-age=31536000";

    root /var/www/public_html;
    index index.php index.html index.htm;

    server_name domain.com www.domain.com;
    ssl on;
    ssl_certificate /etc/ssl/ssl-bundle.crt;
    ssl_certificate_key /etc/ssl/myserver.key;
    ssl_dhparam /etc/ssl/dhparams.pem;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    #Disables all weak ciphers
    ssl_ciphers "ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES128-SHA256:DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES256-GCM-SHA384:AES128-GCM-SHA256:AES256-SHA256:AES128-SHA256:AES256-SHA:AES128-SHA:DES-CBC3-SHA:HIGH:!aNULL:!eNULL:!EXPORT:!DES:!MD5:!PSK:!RC4";

    ssl_prefer_server_ciphers on;
    client_max_body_size 20M;

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

    location ~ \.php$ {
            try_files $uri =404;
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_index index.php;
            include fastcgi_params;
        }

    location ~*  \.(jpg|jpeg|png|gif|ico|css|js|svg)$ {
            expires 30d;
        }
}

顺便说一句,此设置使我的域 ssl 在 ssltestlab 中为 A+

于 2016-03-11T10:17:29.867 回答
0

您的证书很可能仅针对 example.com 颁发,对 www.example.com 无效。重定向,就像您在 NGINX 配置中的重定向一样,仅在您的浏览器抱怨的 TLS/HTTPS 握手之后发生。

您需要请求您的证书颁发者颁发对 example.com 和 www.example.com 都有效的新证书。大多数发行人一开始就应该这样做并且不收取任何费用。

于 2016-03-10T21:13:22.050 回答