7

Is there a way to specify, for example, that the root should be relative to the directory where the config file is living? Something like

root $conf_path/www

2 Answers 2

10

You can actually do that using the -p option.

If you have your config file in the same directory as your app you can run:

/your/folder $ sudo nginx -c `pwd`/nginx.conf -p "`pwd`"

from your app folder.
Your nginx.conf file changes from:

http {
    include mime.types;
    root /your/folder;
    server {
        listen 8000;
    }
}

to

http {
    include /etc/nginx/mime.types;
    root .;
    server {
        listen 8000;
    }
}

just make sure that you check relative links that pointed to /etc/nginx/

Sign up to request clarification or add additional context in comments.

Comments

0

In general, I don't believe this is possible. But, you might be able to hack something together based on this article.

Quoting relevant parts:

2ed version is here: How to reference OS Environment Variables in nginx.conf

Posted at Nginx Forum: http://forum.nginx.org/read.php?2,215269,215278#msg-215278

and further

You can read system environment variables with ngx_lua enabled in your nginx build: http://wiki.nginx.org/HttpLuaModule

env PATH;
http {
    ...
    server {
        location /path {
            set_by_lua $path 'return os.getenv("PATH")';
            ...
        }
    }

BTW, to use the set_by_lua directive, you also need to enable the ngx_devel_kit module here: https://github.com/simpl/ngx_devel_kit (it'll be easier if you use the ngx_openresty bundle).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.