Based on my understadning of the doc, server_name decides which server block will be used.
I have an AWS EC2 instance, and my nginx setup is like the following, where I just simply want to redirect all http requests to https. However, my server_name was mistakenly setup as the following instead of example.com.
server {
listen 80;
server_name ip-xxx-xx-xx-xx.example.com;
return 301 https://example.com$request_uri;
}
However, when I go to http://example.com, I do get redirect to https://example.com, I wonder why that is happening, shouldn't nginx fail to match my http request to that server block since the server_name is not example.com?