Nginx: root path relative to conf file

Is it possible to specify root path relative to the containing conf file?

We are developing a web app and keep app-nginx.conf file with app-specific configuration in the project's directory. I want to be able to include this file into main nginx.conf and have root path properly referencing required project's sub-directory. Example:

# /etc/nginx/nginx.conf
http {
    include /absolute/path/to/app/app-nginx.conf
}


# /absolute/path/to/app/app-nginx.conf
server {
    server_name localhost;
    listen 9090;

    root ./app;
}

After starting nginx with similar configuration nginx tries to resolve ./app path relative to nginx installation directory (/usr/local/Cellar/nginx/1.4.3/ in my case), not to the app's directory.


Solution 1:

Is it possible to specify root path relative to the containing conf file?

Short answer: No.

Long answer: Nginx, by default, only knows about the path such as --prefix and --conf-path that are set at the compile time (ref: https://nginx.org/en/docs/configure.html). We can find various paths used by Nginx by running the command nginx -V (it's capital "V"). So, --conf-path is where the main nginx.conf file resides and that path is used for any relative paths.

According to the official documentation (https://nginx.org/r/root), a root directive can contain other variables, though.

Thanks for @cyker for clarifying after 5 years of posting the initial answer!