Nginx not resolving server_name properly
I have 5 separate domains hosted on godaddy, all which I have put in the DNS manager using this guide
ns1.linode.com
ns2.linode.com
ns3.linode.com
ns4.linode.com
ns5.linode.com
The linode OS I use is archlinux, and I put the same hostname in /etc/rc.conf, /etc/hosts and /etc/rc.d/conf
server {
listen 80;
server_name HOST_A;
location / {
root PATH_A;
index index.html index.htm;
}
}
server {
listen 80;
server_name HOST_B;
location / {
root PATH_B;
index index.html index.htm;
}
}
server {
listen 80;
server_name HOST_C;
location / {
root PATH_C;
index index.html index.htm;
}
}
server {
listen 80;
server_name HOST_D;
location / {
root PATH_D;
index index.html index.htm;
}
}
server {
listen 80;
server_name HOST_E;
location / {
root PATH_E;
index index.html index.htm;
}
}
If I comment out every single server bar one, then it works fine, otherwise it always defaults to the first parsed server
Log files for nginx don't show anything
I think this may be a DNS issue, where the hostname isn't actually being sent to nginx, but instead an IP
To be sure, one doesn't actually require an FQDN for the site to work in /etc/hosts (I have multiple seperate domains hosted on the same site)?. Is the FQDN also something you completely make up?
Any ideas?
5 Replies
The role DNS serves in terms of web browsing is only to translate the "host" part of the URL (if it's not already an IP) to an IP address, which is what can actually be connected to.
What the browser sends to the web server as the Host header depends only on the URL in the location field in the browser.
If you're saying that you do get contact with your server, and specifically nginx running on it, for all those domains, then it would not seem to be a DNS issue.
Can you give actual real-world examples, maybe that would give a better idea of what is going on?
If I happen to comment out HOSTA (so I just have HOSTB,HOSTC,HOSTD, HOSTE) then it just directs to HOSTB
@deteego:
Well the real world example is, that with the config file above, whenever someone puts HOSTA, HOSTB, HOSTC, HOSTD, HOSTE into their browser, it always directs to HOSTA.
If I happen to comment out HOSTA (so I just have HOSTB,HOSTC,HOSTD, HOSTE) then it just directs to HOSTB
When you say "directs to", does it mean that nginx simply serves the content that belongs to the other site or is the browser redirected to the other address?
(Do you have any rewrite rules in place?)
Still, real-world examples would help for anyone but you to actually have a chance of looking at it.
Although something is weird is happening now, some sites just randomly started working (although not all).
I started refreshing the pages in realtime, and they started working (without even updating the nginx config file). I think it really was the DNS updating, I was about to post that every site works except for one, however they all now work! (hence the comment above
Although as you said, that is odd, if the DNS doesn't update probably it shouldn't reach my linode server at ALL
Great that it works, nonetheless!