我想对多个端口使用相同的上游定义:
upstream production {
server 10.240.0.26;
server 10.240.0.27;
}
server {
listen 80;
server_name some.host;
location / {
proxy_pass http://production:1234;
}
}
server {
listen 80;
server_name other.host;
location / {
proxy_pass http://production:4321;
}
}
Run Code Online (Sandbox Code Playgroud)
使用该配置nginx -tthrows:upstream "production" may not have port 1234并返回退出代码 1。
当我尝试将proxy_passURL(或部分)定义为如下变量时:
set $upstream_url "http://production:1234"
set $upstream_host production;
set $upstream_port 1234;
proxy_pass $upstream_url;
# or
proxy_pass http://production:$upstream_port;
# or
proxy_pass http://$upstream:$upstream_port;
Run Code Online (Sandbox Code Playgroud)
Nginx 尝试通过解析器解析我的上游名称:
*16 no resolver defined to resolve production, client: …Run Code Online (Sandbox Code Playgroud) nginx ×1