Nginx returning 404 on seemingly valid path

http-status-code-404nginxopenbsd

I'm trying to serve static files directly with a location block like this:

location /static/ {
    alias /opt/graphite/webapp/content/;
}

But when I make a request for anything matching /static/, I get a 404 error, and a message like this in the error log:

2016/09/14 09:28:47 [error] 66068#0: *4 open() "/opt/graphite/webapp/content/js/completer.js" failed (2: No such file or directory), client: my.ip.add.ress, server: server.domain, request: "GET /static/js/completer.js HTTP/1.1", host: "server.ip", referrer: "http://server.ip/composer?"

The thing is that the path given in that error message is completely valid. That file exists. It's not claiming permission denied, so it doesn't seem like a permissions issue. The location that proxies to the app works fine. I'm at a loss, and similar posts all seem to pertain to sockets.

Running nginx 1.10.1 on OpenBSD 6.0.

Best Answer

Figured this out. The distribution of nginx in OpenBSD defaults to chrooting into /var/www/, which denies access to the entire filesystem outside of that section. This can be circumvented by starting nginx directly with the -u flag, or adding that same flag to the command in /etc/rc.d/nginx.

Alternatively, moving everything into the chroot is pretty trivial, once you know that's what's happening.