0

I replicated an EC2 instance on AWS because the owner lost the pem file and couldn't SSH in. It has two sites configured, but when I access this server via its public DNS, it serves me one of the sites. How does it know to pick the site it serves me? I don't see any configuration that would indicate one of the sites is the default one (something like listen 80 default).

In /etc/nginx/sites-available (in order):

default
new-site
site

In /etc/nginx/sites-enabled (in order):

new-site
site
3

If you are browsing to a proper hostname, your browser will send a Host header to the server. Then, if there's a matching vhost (look at the server_name directives), nginx will serve that vhost.

If you're browsing to the server IP or if you are browsing to a hostname that does not match any of the server_name directives, it will serve the default vhost or whichever vhost file it loaded first (by alpha order).

Note: if these are HTTPS connections, SNI is also involved.

4
  • I was accessing it via http://ec2-xxx.us-west-1.compute.amazonaws.com. It doesn't match any server_names, so alphabetical order I take it. – musicliftsme Jan 9 '17 at 20:02
  • @musicliftsme Yep, that's correct. – EEAA Jan 9 '17 at 20:02
  • Its only looking at sites-avaliable it seems? The default config has server_name localhost which seems like it won't do anything in terms of serving pages to the browser from the outside. – musicliftsme Jan 9 '17 at 20:08
  • sites-enabled are the active sites. – EEAA Jan 9 '17 at 20:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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