Score:0

SSL subdomain doesn't redirect

cn flag

I am trying to visit app.example.com.

  1. When I type app.example.com, it goes to example.com.
  2. If I type https://app.example.com, it goes to app.example.com.

Why is the first happening?

Here's the nginx.conf

# APP =====================================================

server {
    listen 80;
    server_name app.example.com; 

    return 301 https://app.example.com$request_uri;
}

server {
    listen 443 ssl;
    server_name app.example.com;

    ssl_certificate /etc/letsencrypt/live/app.example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/app.example.com/privkey.pem;

    location / {
        proxy_pass 'http://127.0.0.1:3000';
    }
}

# WEBSITE =====================================================

server {    
    listen 80;
    server_name example.com www.example.com;

    return 301 https://example.com$request_uri;
}

server {
    listen 443 ssl;
    server_name www.example.com;

    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;

    return 301 https://example.com$request_uri;
}

server {
    listen 443 ssl;
    server_name example.com;

    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;

    location / {
        proxy_pass 'http://127.0.0.1:3002';
    }
}
Steffen Ullrich avatar
se flag
A permanent redirect (code 301) gets cached by the browser. If you had a 301 redirect for app.example.com to example.com in the past then the browser will not check again but use the already cached redirect and visit the target directly. Check with an incognito window to make sure that existing caches will not be used. To delete cached entries from your main browser profile clear the caches.
Ivan avatar
cn flag
Niiiiiice. That was the issue! Thank you so much. Can you please post it as an answer so I can accept it.
Steffen Ullrich avatar
se flag
Somebody came just up with a good answer on how to tackle such problems: [My browser will not display http://\[sub.\]example.com](https://serverfault.com/questions/1092950/my-browser-will-not-display-http-sub-example-com)
Ivan avatar
cn flag
That was a great read. Thank you for the suggestion.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.