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 load https://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 to mydomain.com?

If so, how do I differentiate requests to www.mydomain.com and mydomain.com at my server?

  • Unless you're using newfangled SNI, that's how it works. The hostname is part of the encrypted payload - name-based virtualhosts don't work with SSL.
    – ceejayoz
    Aug 22, 2014 at 21:05

1 Answer 1


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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.