0

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';
    }
}
Ivan
  • 109
  • 6
  • 1
    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. – Steffen Ullrich Feb 06 '22 at 17:07
  • Niiiiiice. That was the issue! Thank you so much. Can you please post it as an answer so I can accept it. – Ivan Feb 07 '22 at 00:42
  • 2
    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) – Steffen Ullrich Feb 07 '22 at 19:24
  • That was a great read. Thank you for the suggestion. – Ivan Feb 08 '22 at 01:26

0 Answers0