I have my Nginx conf set up as follows:
server { listen 443 ssl; server_name mydomain.com; ... }
When I load
https://mydomain.com
, the site loads fine.
But when I loadhttps://www.mydomain.com
, the site loads as well. Why is this happening?I set up the DNS records using Amazon Route 53 as:
A mydomain.com xxx.xxx.xxx.xxx (IP) CNAME www.mydomain.com mydomain.com
So is a request to
www.mydomain.com
arriving at Nginx as a request tomydomain.com
?If so, how do I differentiate requests to
www.mydomain.com
andmydomain.com
at my server?
Answer
If this is the only server
block that listens to port 443, it is used for all SSL connections to the server, independent of the actual domain name.
You need to make a server
block with listen 443 ssl default_server
entry to make a virtual host that is served when no other server
block matches.
Attribution
Source : Link , Question Author : Lorenz Forvang , Answer Author : Tero Kilkanen