是否可以在 nginx 上游指令中使用变量?
upstream appserver {
server unix:/socks/$host.sock
}
Run Code Online (Sandbox Code Playgroud)
我已经搜索了我的小心脏,找不到答案。
A) 有可能吗?
B) 这是一个糟糕的主意吗?
进行这种配置通常是一个坏主意。
您最好执行以下操作:
一般配置:
http {
...
include upstreams/*.conf;
...
server {
...
Run Code Online (Sandbox Code Playgroud)
上游/*.conf:
使用脚本生成这些文件,并为您更改变量,然后重新加载配置 nginx -s reload
示例python脚本:
from os import system
upstream = "something"
with open('upstreams/bro.conf', 'w') as f:
f.write('upstream {0} {{\n\tserver unix:/socks/{0}.sock\n}}'.format(upstream)
system('nginx -s reload')
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6720 次 |
| 最近记录: |