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

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.

share|improve this question

migrated from superuser.com Oct 24 '13 at 12:02

This question came from our site for computer enthusiasts and power users.

2 Answers 2

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

No.

Nginx, by default, only knows about the path set as --prefix at the compile time (ref: http://nginx.org/en/docs/configure.html). So, that path is used for any relative paths.

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

share|improve this answer
    
Thank you, Pothi. Unfortunately neither of the options works for me. --prefix can affect other nginx servers and from my personal perspective a little bit harder to manage comparing to configuration file. And nginx doesn't allow to create custom variables with set directive outside server context, so I can't move absolute path from my app-nginx.conf file. –  Anton Moiseev Oct 24 '13 at 13:57

I haven't found a way to use relative paths or define global variables, but this little trick solves my problem.

share|improve this answer
    
What little trick? –  Michael Hampton Oct 24 '13 at 16:40
    
I can't define variable, but I can use map directive with single default value that will play role of the variable for me. –  Anton Moiseev Oct 25 '13 at 19:15

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.