Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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!

share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

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;
share|improve this answer
    
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. –  Bepetersn Sep 15 '13 at 2:21
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.