Forum: NGINX Nginx server_name command being ignored

Posted by constable1 (Guest)
on 2012-12-14 14:02
(Received via mailing list)
Hi, I'm running ubuntu server 12.04 and the latest version of nginx. The
problem I am having is that nginx seems to be ignoring the server_name
command, I am able to access the server by going to the IP address of 
the
server or by going to the server's name (http://ubuntuserver/) but
http://test/ will give me nothing, no connection, not even an error 
page. I
have checked that the website file (in enabled-sites) is included in the
nginx.conf file and I have correctly restarted nginx having changed
settings. I have tried with the whole server block stripped down to just 
the
server_name designation and still I can't get anything at http://test/ 
and
in this case I get an expected error page on http://ubuntuserver/

I can only deduce that for some reason the "server_name" command is 
being
ignored!

If anyone could give me any advice with regards to this then it would be
much appreciated.

Code from file "www" in "enabled-sites":

server {
      add_header  Cache-Control public;
      access_log  /var/log/nginx/access.log main buffer=32k;
      error_log   /var/log/nginx/error.log error;
      expires     max;
      limit_req   zone=gulag burst=200 nodelay;
      listen      127.0.0.1:80 sndbuf=128k;
      root        /usr/share/nginx/html;
      server_name test;
}

Posted at Nginx Forum: 
http://forum.nginx.org/read.php?2,234028,234028#msg-234028
Posted by Antonio P.P. Almeida (Guest)
on 2012-12-14 14:09
(Received via mailing list)
> server_name designation and still I can't get anything at http://test/ and
> in this case I get an expected error page on http://ubuntuserver/
>
> I can only deduce that for some reason the "server_name" command is being
> ignored!
>

Is there a resolver (DNS or /etc/hosts) for test?

What does ping test gives?

--appa
Posted by Jonathan Matthews (Guest)
on 2012-12-14 14:10
(Received via mailing list)
On 14 December 2012 13:01, constable1 <nginx-forum@nginx.us> wrote:
>
> I can only deduce that for some reason the "server_name" command is being
> ignored!

I really doubt it is. It's an absolute cornerstone of how nginx works.

a) Does your machine resolve the correct IP address when asking your
hostsfile/DNS/etc for "test"? server_name doesn't automatically point
your browser towards the correct machine ...

b) The first server{} stanza for an IP:port pair is the default one
served when a request comes in on that IP and port, and the Host
header doesn't match /another/ server_name configured elsewhere for
that same IP and port. Unless there's a dedicated default server ...

You may wish to set up a sacrificial default server to make nginx's
behaviour more obvious.
This is roughly what I have (typed but not tested, FYI):

server {
  listen 80 default_server;
  server_name _;
  return 400 "Server not configured";
}

HTH,
Jonathan
--
Jonathan Matthews // Oxford, London, UK
http://www.jpluscplusm.com/contact.html
Posted by constable1 (Guest)
on 2012-12-14 14:13
(Received via mailing list)
I've tried pinging http://test/ and get nothing, I'll have a go with 
your
suggestion Jonathan and report back!

Posted at Nginx Forum: 
http://forum.nginx.org/read.php?2,234028,234032#msg-234032
Posted by Francis Daly (Guest)
on 2012-12-14 14:14
(Received via mailing list)
On Fri, Dec 14, 2012 at 08:01:33AM -0500, constable1 wrote:

Hi there,

> I am able to access the server by going to the IP address of the
> server or by going to the server's name (http://ubuntuserver/) but
> http://test/ will give me nothing, no connection, not even an error page.

What is the output of

  curl -i http://test/

?

My guess is that your browser fails to resolve the name to the correct
address, and so never talks to nginx in the first place.

If that is the case, make the name resolvable -- put it in DNS or
/etc/hosts, for example -- and retry the curl command.

If it does not show what you expect, describe that output too.

  f
--
Francis Daly        francis@daoine.org
Posted by Jonathan Matthews (Guest)
on 2012-12-14 14:18
(Received via mailing list)
On 14 December 2012 13:12, constable1 <nginx-forum@nginx.us> wrote:
> I've tried pinging http://test/ and get nothing

Just do "ping test". Not "ping http://test/"

> I'll have a go with your
> suggestion Jonathan and report back!

My suggestion for a default server will not fix your inability to
resolve the site's name. It's just a sanity thing you'll find useful
if you set up more server{}s over time. You need to fix the DNS/etc
issue, once you prove it exists as per the above.

Jonathan
--
Jonathan Matthews // Oxford, London, UK
http://www.jpluscplusm.com/contact.html
Posted by Francis Daly (Guest)
on 2012-12-14 14:33
(Received via mailing list)
On Fri, Dec 14, 2012 at 01:13:44PM +0000, Francis Daly wrote:
> On Fri, Dec 14, 2012 at 08:01:33AM -0500, constable1 wrote:

Hi there,

> What is the output of
>
>   curl -i http://test/
>
> ?
>
> My guess is that your browser fails to resolve the name to the correct
> address, and so never talks to nginx in the first place.

Oh, if that is the case, then you can still test the nginx side without
fixing name resolution by looking at the output of

  curl -i -H Host:test http://127.0.0.1/

and confirming that it is what you expect.

  f
--
Francis Daly        francis@daoine.org
Posted by constable1 (Guest)
on 2012-12-15 00:55
(Received via mailing list)
Hi Jonathan, Francis,

I've just tried on the server "ping test", and I get no packet loss, it 
all
seems to be looking fine. I also tried "curl -i http://test/" and I get 
the
output as the code that makes up the html of my page, so it appears that
nginx is working fine, but when I try going to http://test/ on another
machine on my home network then I get nothing, I agree that this must be
some kind of DNS issue here, but how does one go about fixing it?

Cheers,
Matt

Posted at Nginx Forum: 
http://forum.nginx.org/read.php?2,234028,234062#msg-234062
Posted by Jonathan Matthews (Guest)
on 2012-12-15 01:23
(Received via mailing list)
On 14 December 2012 23:54, constable1 <nginx-forum@nginx.us> wrote:
> Hi Jonathan, Francis,
>
> I've just tried on the server "ping test", and I get no packet loss, it all
> seems to be looking fine. I also tried "curl -i http://test/" and I get the
> output as the code that makes up the html of my page, so it appears that
> nginx is working fine, but when I try going to http://test/ on another
> machine on my home network then I get nothing, I agree that this must be
> some kind of DNS issue here, but how does one go about fixing it?

Work put how the machines *should* be resolving "test" to an IP
address, and add entries so that they *can*.
This may be your hosts file, if you're doing internal, LAN-only
development, or a DNS server somewhere.

This is somewhat of out of scope for the nginx list now, though ... :-)

HTH,
Jonathan
--
Jonathan Matthews // Oxford, London, UK
http://www.jpluscplusm.com/contact.html
Posted by constable1 (Guest)
on 2012-12-15 02:20
(Received via mailing list)
Jonathan, I've added to the host file of my server 127.0.0.1 test, but 
still
have no luck locally. I have also tried port forwarding from my router 
(port
80 to port 80) and am unable to then connect to my server using my 
public IP
address. Do you know if there are any forums which could help me in this
regard?

Cheers

Posted at Nginx Forum: 
http://forum.nginx.org/read.php?2,234028,234064#msg-234064
Posted by Francis Daly (Guest)
on 2012-12-15 12:06
(Received via mailing list)
On Fri, Dec 14, 2012 at 06:54:58PM -0500, constable1 wrote:

Hi there,

> I also tried "curl -i http://test/" and I get the
> output as the code that makes up the html of my page, so it appears that
> nginx is working fine, but when I try going to http://test/ on another
> machine on my home network then I get nothing,

Exactly the same as the last time:

What is the output of

  curl -i http://test/

? Do that from whatever machine you want things to work from. The output
is unlikely to be "nothing", and is likely to give an indication of the
first problem.

And you can still test the nginx side without fixing name resolution by
looking at the output of

  curl -i -H Host:test http://127.0.0.1/

where "127.0.0.1" should be replaced with "an ip address that the nginx
server is listening on".

Note that 127.0.0.1 is a special address which means (roughly) "this
machine only". And so is unlikely to work from any other machine.

The server{} block that has "server_name test" would need to "listen"
on a non-127.0.0.1 address for it to be accessible

> I agree that this must be
> some kind of DNS issue here, but how does one go about fixing it?

"Big" fix is "whatever your network does". "Small" fix is /etc/hosts.

  f
--
Francis Daly        francis@daoine.org
Posted by constable1 (Guest)
on 2012-12-15 12:32
(Received via mailing list)
Hi Francis,

I am trying to access the web server from a bunch of windows machines (I
don't have any linux desktops). My /etc/hosts file already reads:
127.0.0.1 localhost
127.0.1.1 ubuntuserver
192.168.1.93 test

Where the final address is the local address of the server. When I do 
the
curl operation from the server on http://test/ then I get the index.html
page back, which is encouraging, but when I try to ping it from any of 
my
windows machines then I get nothing.

Posted at Nginx Forum: 
http://forum.nginx.org/read.php?2,234028,234073#msg-234073
Posted by Francis Daly (Guest)
on 2012-12-15 12:47
(Received via mailing list)
On Sat, Dec 15, 2012 at 06:32:07AM -0500, constable1 wrote:

Hi there,

> I am trying to access the web server from a bunch of windows machines (I
> don't have any linux desktops). My /etc/hosts file already reads:
> 127.0.0.1 localhost
> 127.0.1.1 ubuntuserver
> 192.168.1.93 test

/etc/hosts is for local-to-this-machine name resolution. It is the 
client
machine -- the one running the web browser -- that needs to resolve the
name "test" to the ip address.

So if you try on a windows machine, you must have the "test" entry in
the /etc/hosts file on that windows machine. Searching the fine web
should tell you exactly which file that corresponds to on the version
of windows that you are using.

> Where the final address is the local address of the server. When I do the
> curl operation from the server on http://test/ then I get the index.html
> page back, which is encouraging, but when I try to ping it from any of my
> windows machines then I get nothing.

When you type "curl -i http://test/" from a command shell on any one
windows machine, you get immediately returned to the prompt with no
other output? Likewise when you use the other curl command suggested?

That is unexpected to me and I do not know how to proceed.

  f
--
Francis Daly        francis@daoine.org
Posted by constable1 (Guest)
on 2012-12-15 13:02
(Received via mailing list)
Francis, forgive me, I was accidentally editing the host file on the 
wrong
machine, stupid mistake, I've now got it sorted and working for a public 
IP
now.

Thanks for all of your help Jonathan, Francis!

Posted at Nginx Forum: 
http://forum.nginx.org/read.php?2,234028,234075#msg-234075
Posted by Francis Daly (Guest)
on 2012-12-15 15:12
(Received via mailing list)
On Sat, Dec 15, 2012 at 07:01:45AM -0500, constable1 wrote:

Hi there,

> Francis, forgive me, I was accidentally editing the host file on the wrong
> machine, stupid mistake, I've now got it sorted and working for a public IP
> now.

No worries; "sorted and working" is good news..

Good stuff,

  f
--
Francis Daly        francis@daoine.org
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.