Nginx location directive

PDStat asked:

I have a .conf file existing in /etc/nginx/conf.d similar to the below

server {
    location /config/ {
        root /app/services/config;
        try_files $uri $uri/ $uri/config.json =404;
    }
}

config.json exists in /app/services/config however when my URI to the server is /config/config.json I am getting a 404 error.

My answer:


The path in the URL request is appended to the filesystem path in the root directive, and the result is the path which is used to find the file.

In the case you illustrated, this results in:

/app/services/config/config/config.json
____________________ __________________
root                 URL

So, you must either place your files there, or change the URL path, or change the path in the root directive.


View the full question and any other answers on Server Fault.

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