Nginx not resolving server_name properly

I just started a linode server, and I seem to have an issue where no matter what domain name I put into a website (that is registered with linode in the DNS manager), nginx always returns the same website for the virtual server HOST_A (or whatever happens to be the first parsable hostname when I messed around with it). I have been trying to fix this for a couple of hours, but I have no idea if this is due to the way I have my dns set up or due to nginx (however at this point I am leaning towards the former)

I have 5 separate domains hosted on godaddy, all which I have put in the DNS manager using this guide http://www.linode.com/wiki/index.php/Linode_DNS. I just updated the nameservers at godaddy with

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

I can't really solve the problem but I can rule out a few things.

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?

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

@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.

Yes I mean that nginx just serves the content of that site

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

Based on your description I don't really think it was DNS, possibly browser cache if your nginx configuration was different originally.

Great that it works, nonetheless!

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct