@narcuri1
Each domain needs to be setup with the proper DNS entries. This would consist of at least one A
entry and one CNAME
entry, which would look like:
NOTE: domain.ext
= your actual domain name and DROPLET_PUBLIC_IP
= your Droplets Public IP Address.
A @ DROPLET_PUBLIC_IP
CNAME www domain.ext.
Optionally, you can add an additional A
entry which is referred to as a WildCard. It's simply an A
entry that sets an asterisk (i.e. *) to point to your Droplets Public IP.
A * DROPLET_PUBLIC_IP
... so all together:
A @ DROPLET_PUBLIC_IP
A * DROPLET_PUBLIC_IP
CNAME www domain.ext.
Now, if you prefer not to use the WildCard, your server_name
directive should always be set as:
server_name domain.ext www.domain.ext;
If you choose to use the WildCard (best option, IMO), then your server_name
directive (for each server
block) would look like:
server_name domain.ext *.domain.ext;
We're simply replacing www
with *
in the server_name
directive, that's it :-).
The benefit of using the WildCard setup instead of the typical www
is that when you visit a a URI that does not exist, if a WildCard is setup, it'll route that request to the primary domain, thus, no error. If you do not use a WildCard, when someone tries to access invalid-subdomain.yourdomain.ext
(i.e. a sub-domain that isn't setup / does not exist), they'll be met with a 404 (or whatever error is standard for your setup).
The WildCard simply helps in making sure that any requests that would normally be invalid or display and error are routed to your domain instead. This, IMO, keeps the error logs cleaner (and smaller).
NOTE: www
is considered a "sub-domain", as is anything that is placed before your domain (i.e. anything.yourdomain.ext
). So if you use the WildCard, technically, you do not need the CNAME
for www
.
--
Once you make the above changes, DNS can take up to 24-48 hours to update, so such changes may not be immediately available. If nothing is working after 24-48 hours, then here what we need to look at:
1). Copy & Paste, verbatim, both server
blocks. You can replace the domains. They really don't matter as long as you can adjust the configuration I provide you with by replacing my configuration with your actual config :-).
2). Copy & Paste, verbatim, your DNS Zone entries for each domain name (specifically your A
and CNAME
entries). If you have any DNS entries that modify routing in any way, or you're unsure, please post the entire DNS Zone (screenshots are fine).
--
I'd recommend PasteBin for #1 and Imgur for #2. This just keeps thing clean :-).
The
server_name
directive in the server blocks you provided is what controls this behavior. Fix your second site so that it includes the domain you want it to respond to.I have:
for the second site. Is that not right?
*edit: I just realized I typed
server_name site1.com www.site1.com
in my original post. I meant site2 so I think what I have is correct.Honestly, if you insist on redacting the domain names, there's nothing I can do to help. This is really a matter of typing it correctly on the site involved and making sure DNS resolves to that web server. Make sure you reload the web server after making the changes and that the files are being read correctly by nginx.
I'm not insisting anything. I felt it was easier to write and I can't edit my original post to change it. You really can't do anything unless you know the exact domain name? The
server_name
's reflect the domains that they should resolve to. In any case I found a solution and have answered my own question.