0

EDIT:

I figured this out, see first answer below


I have a fairly simple test config for an NGINX server that proxies to a Tornado server:

    server {
        listen       80;
        server_name  _;

        location = / {
            proxy_set_header   X-Real-IP        $remote_addr;
            proxy_pass   http://127.0.0.1:8901/;
        }

        error_page  404              /404.html;
        location = /404.html {
            root   /usr/share/nginx/html;
        }

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /usr/share/nginx/html;
        }
    }

Simple enough, when I access http://myserver.com/ it all works fine, but if I access http://myserver.com/somefile.html it triggers a 404, and in the error log it says

2011/06/06 18:39:24 [error] 23948#0: *100 open() "/usr/share/nginx/html/somefile.html" failed (2: No such file or directory), client: 1.1.1.1, server: _, request: "GET /somefile.html.html HTTP/1.1", host: "myserver.com"

Which looks as though NGINX isn't passing /somefile.html on to the proxy. Going directly to http://myserver.com:8901/somefile.html works fine, and if I create /usr/share/nginx/html/somefile.html NGINX shows the contents of that file instead of proxying to the correct server.

I can't remember this ever happening before on any of my NGINX servers so I'm completely confused

If it's of any use, it's NGINX 0.7.67 on RHEL 5.5

4
  • Just FYI, the tutorial you've been following is wrong. server_name _ does not create a "catch all" server block. The reason it probably seems like that is Nginx will use the first server block specified if none match. So if you ever add another server block before that one you will be confused. Jun 6, 2011 at 22:55
  • @Martin I'm not following a tutorial, I built the config from memory (Hence why it didn't work haha). There is only one server{} block in the config anyway, and there will never be any more.
    – user80776
    Jun 6, 2011 at 23:21
  • Then the tutorial you read back then is wrong. :) I still suggest you remove the server_name and instead use the default_server flag on listen, in my experience "never" really means "no plans to" and "no plans to" turns into "plans got changed". Jun 7, 2011 at 12:15
  • @Martin I can absolutely assure you 100% that this server will never have more than one VHost on =) It's just an EC2 dev box, my NGINX configs for live servers actually work haha (Also we don't use virtual hosts, we just get a unique IP for each site, our server came with 38 IPs so instead of using server_name we do listen 1.2.3.4:80; with a different IP for each host. Interestingly when we got rid of virtual hosts the load on our server dropped, only slightly but it was still noticeable so I concluded vhosts are an unnecessary overhead when we've got a big-ish netblock).
    – user80776
    Jun 7, 2011 at 12:56

1 Answer 1

1

Oh #fail

For the purposes of educating anyone else as stupid as me, using

location = / {

will match only / but using

location / {

will match the directory / (Including all sub-folders/files etc.)

You must log in to answer this question.