0

ドメインのすべてのトラフィックを 1 つのターゲットにリダイレクトしたい: 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;
} 

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

私たちが抱えている問題は、チェックアウトしたすべてのリダイレクトと書き換えルールが、次の 3 つのケースでうまく機能したことです。

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 

ブラウザーでは、ターゲット SSL ドメインhttps://example.comの代わりにhttps://www.example.comが表示されます。

この場合、SL 証明書に「信頼されていない」というメッセージが表示されます

仮想ホストの構成は、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 に答える