Nginx error log shows strange results

Brian Peterson asked:

Here’s my Nginx config, in brief:

...

server {
    listen   80;
    server_name whatever;
    root /var/www/;

    location /api/1.0 {
        ...
        `proxy_pass http://localhost:8000/;
    }

    location /api/2.0 {
        ...
        proxy_pass http://localhost:8080/;
    }

    location / {
        root /var/www/static/;
        default_type text/html;
        try_files  $uri $uri/index.html index.html;
    }
}

If I now go to localhost, and append a random name that doesn’t correspond to anything in my static files, or mean anything in either of two applications (e.g. http://localhost/whatever), I get a strange error in my log:

2013/09/14 20:58:20 [error] 28731#0: *2 open() “/var/wwwindex.html” failed (2: No such file or directory), client: 127.0.0.1, server: ec2-54-234-175-21.compute-1.amazonaws.com, request: “GET /whatever HTTP/1.1”, host: “localhost”

I’m thinking this must just reflect my lack of understanding, because I really have no idea why nginx is trying to access “/var/wwwindex.html”. Note that I don’t want this request to succeed, I just want it to fail in a way I understand. What exactly is happening? Thoughts appreciated, thanks in advance!

My answer:


Your try_files ends with index.html, which is appended to the root (and the trailing / on the root is ignored). Add a / to it.

        try_files  $uri $uri/index.html /index.html;

View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.