配置文件路径的nginx变量

Jar*_*yth 4 config nginx

例如,有没有办法指定root应该相对于配置文件所在的目录?就像是

root $conf_path/www
Run Code Online (Sandbox Code Playgroud)

Ren*_*aud 8

您实际上可以使用该-p选项来做到这一点。

如果您的配置文件与您的应用程序位于同一目录中,则可以运行:

/your/folder $ sudo nginx -c `pwd`/nginx.conf -p "`pwd`"
Run Code Online (Sandbox Code Playgroud)

从您的应用程序文件夹。
您的nginx.conf文件更改自:

http {
    include mime.types;
    root /your/folder;
    server {
        listen 8000;
    }
}
Run Code Online (Sandbox Code Playgroud)

http {
    include /etc/nginx/mime.types;
    root .;
    server {
        listen 8000;
    }
}
Run Code Online (Sandbox Code Playgroud)

只要确保您检查指向的相关链接 /etc/nginx/


CDu*_*Dub -1

总的来说,我认为这是不可能的。但是,您也许可以根据这篇文章来破解一些东西。

引用相关部分:

2ed 版本在这里: 如何在 nginx.conf 中引用操作系统环境变量

发布于 Nginx 论坛: http://forum.nginx.org/read.php?2,215269,215278 #msg-215278

并进一步

您可以在 nginx 构建中启用 ngx_lua 来读取系统环境变量:http://wiki.nginx.org/HttpLuaModule

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

顺便说一句,要使用 set_by_lua 指令,您还需要在此处启用 ngx_devel_kit 模块:https://github.com/simpl/ngx_devel_kit (如果您使用 ngx_openresty 包会更容易)。