如何强制将www重定向到非www SSL子域

时间:2016-08-16 22:00:56

标签: redirect ssl nginx https subdomain

如果有人愿意向我提供有关如何让NGINX发挥出色的提示,我会很高兴。我想重新定位https://www.subdomain.domain.com,但不幸的是,我现在没有为我工作。

请考虑我在 / etc / nginx / sites-available / default

中设置的NGINX的以下设置
server {
     listen 443 ssl;

     server_name subdomain.domain.com;

     ssl_certificate /etc/letsencrypt/live/subdomain.domain.com/fullchain.pem;
     ssl_certificate_key /etc/letsencrypt/live/subdomain.domain.com/privkey.pem;
     ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
     ssl_prefer_server_ciphers on;
     ssl_dhparam /etc/ssl/certs/dhparam.pem;
     ssl_ciphers 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-$
     ssl_session_timeout 1d;
     ssl_session_cache shared:SSL:50m;
     ssl_stapling on;
     ssl_stapling_verify on;
     add_header Strict-Transport-Security max-age=15768000;

     server_name subdomain.domain.com; # Replace with your domain
     root /home/dropshare/public_html;
     index index.html index.htm;
     client_max_body_size 10G;

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

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

server {
    listen 443 ssl;
    server_name subdomain.domain.com;
    return 301 https://subdomain.domain.com$request_uri;
}

1 个答案:

答案 0 :(得分:2)

您的配置无效且被nginx拒绝。

您有两个相同的虚拟服务器:

server {
    listen 443 ssl;

    server_name subdomain.domain.com;
...
server {
    listen 443 ssl;
    server_name subdomain.domain.com;

其中一个只是重定向到自己:

server {
    listen 443 ssl;
    server_name subdomain.domain.com;
    return 301 https://subdomain.domain.com$request_uri;
}