Score:1

nginx subdomain wrong redirect

cn flag

I have set up a nginx server with this config:

server {
        server_name key.mydomain.fun;
        location / {
                proxy_pass      http://mydomain.fun:6969;
        }
}
server {
    listen 80;
    server_name admin.mydomain.fun;
    return 301 https://$server_name$request_uri;
}

server {
    listen 443 ssl http2;
    server_name admin.mydomain.fun;
    ....
}

The strange thing is: When starting with a fresh browser and go to "key.mydomain.fun", I get a ssl cert warning that the cert is only valid for "mydomain.fun" and not "key.mydomain.fun". (I have a ssl cert configured for only mydomain.fun, so no wildcard). After accepting I get to the key-page.

After that I want to access "admin.mydomain.fun" and get the error message again (Thats normal) and after accepting I get to my admin page.

Now the strange thing: when I now want to access "key.mydomain.fun" again, the admin site will be displayed. The URL is still "key.mydomain.fun" but I am at the admin page. After that "key.mydomain.fun" and "admin.mydomain.fun" will get me to the admin page.

When I now reset the browser (delete everything) I can redo those steps and access the "key.mydomain.fun" site again.

What went wrong here? Why do I see the admin page when going to "key.mydomain.fun"?

Michael Hampton avatar
cz flag
You don't have a `server` block for `key.mydomain.fun` using TLS on port 443. The default (first) block is used instead.
digijay avatar
mx flag
Also, get valid TLS certificates for all your subdomains, it's easy and free with [letsencrypt](https://certbot.eff.org/)
someone324443 avatar
cn flag
Ok I did that and now everything is working fine. I also updated to a wildcard certificate. But one question, I only have the cert configured in the `admin.mydomain.fun` server block. Why do I still have a valid cert, or a cert in general, at `key.mydomain.fun`?
djdomi avatar
za flag
IMHO you did not said to nginx to what `key.domain.fun` should `listen`
someone324443 avatar
cn flag
@djdomi Do I need to do that? should I just listen to `listen 80 443` ?
djdomi avatar
za flag
[Join the chat](https://chat.stackexchange.com/rooms/126791/thechat) it will make it easier and we do not spam here
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.