Virgil
Virgil

Reputation: 1

How to force redirect www to non-www SSL subdomain

I'd be delighted if someone would kindly provide me with any tips on how to get NGINX to play nice. I want to redirect https://www.subdomain.domain.com but unfortunately that's not working out for me right now.

Please consider the following set up for NGINX that I have in /etc/nginx/sites-available/default

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;
}

Upvotes: 0

Views: 236

Answers (1)

VBart
VBart

Reputation: 15110

Your configuration isn't valid and is rejected by nginx.

You have two identical virtual servers:

server {
    listen 443 ssl;

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

and one of them is just redirecting to itself:

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

Upvotes: 2

Related Questions