更新时间:2022-10-16 22:55:40
通常,我认为这是不可能的.但是,您可能可以根据本文. >
引用相关部分:
2版本在这里: 如何在nginx.conf中引用操作系统环境变量
发布在Nginx论坛上: http://forum.nginx.org/read.php? 2,215269,215278#msg-215278
进一步
您可以在启用了ngx_lua的情况下读取系统环境变量 nginx构建: http://wiki.nginx.org/HttpLuaModule
env PATH;
http {
...
server {
location /path {
set_by_lua $path 'return os.getenv("PATH")';
...
}
}
顺便说一句,要使用set_by_lua指令,您还需要启用 此处的ngx_devel_kit模块: https://github.com/simpl/ngx_devel_kit (如果使用ngx_openresty捆绑包会更容易).
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
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).