0

Scenario

I have a website served by nginx listen at domain myabc.domain.com.

The nginx configuration is:

server {
  listen                      443 ssl;
  server_name                 myabc.domain.com`;
  root                        /home/ubuntu/portal;



  location / {

    # other directives
}

Then I add an A record in DNS server:

myabc.domain.com -> 123.123.123.123

It is working fine.

Then, I add a CNAME record to DNS server

myabc2.domain.com -> myabc.domain.com

I tried accessing the webpage from browser with myabc2.domain.com and it works!?

Question

I expect the nginx server_name to only permit access to this site whose host header is myabc.domain.com.

The host header is set automatically by browsers to be the one I typed in. (I assume)

So why doesn't nginx deny access to this request?

4
  • 1
    "I expect the nginx server_name to only permit access to this site whose host header is myabc.domain.com." Why do you expect that? Commented Dec 10, 2019 at 4:25
  • Thanks. I remember skimming through this directive sometime ago. I should have revised it before asking this question. Apparently, my question describes a specific case when no server with matching server_name is found, the request will be routed to the first server - which is the myabc.domain.com server in my setting. Commented Dec 10, 2019 at 4:37
  • I'll delete this question since it's not likely going to be helpful for others. Commented Dec 10, 2019 at 4:38
  • 1
    You can post what you found as answer. Somebody else might have the same expectation. Commented Dec 10, 2019 at 4:38

1 Answer 1

1

Once again, Assumption is never a good thing. Reading document is the way to go.

Thanks @muru for pointing that out for me.

The answer is that:

My question describes a specific case when no server with matching server_name is found. In such situation, nginx will route the request to the first specified server listening on that port - which is the myabc.domain.com server in my setting.

Ref: Nginx's document

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.