2

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!

1 Answer 1

4

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;
1
  • Thanks! I'm trying to make a bunch of changes to an nginx conf file which I've inherited and hitting a lot of bugs, so for the moment I'm just trying to get everything into a known state. Sep 15, 2013 at 2:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .