NGINX,使用端口号($ server_port)简化配置

时间:2018-10-03 13:11:49

标签: nginx reverse-proxy nginx-reverse-proxy nginx-config

当前,每个端口都有一对上游和服务器块,所有其他详细信息相同:

upstream backend-7777 {
        server XXX.XXX.XXX.XXX:7777;
        server YYY.YYY.YYY.YYY:7777;
}
server {
        listen 7777 ssl;
        server_name abc.def.ghi abc;
        location / {
                proxy_pass https://backend-7777;
        }
}

upstream backend-8888 {
        server XXX.XXX.XXX.XXX:8888;
        server YYY.YYY.YYY.YYY:8888;
}
server {
        listen 8090 ssl;
        server_name abc.def.ghi abc;
        location / {
                proxy_pass https://backend-8888;
        }
}

upstream backend-9999 {
        server XXX.XXX.XXX.XXX:9999;
        server YYY.YYY.YYY.YYY:9999;
}
server {
        listen 9999 ssl;
        server_name abc.def.ghi abc;
        location / {
                proxy_pass https://backend-9999;
        }
}

我想简化配置文件。使用端口号以某种方式只写一个上游块和一个服务器块。

类似这样的东西:

upstream backend {
        server XXX.XXX.XXX.XXX;
        server YYY.YYY.YYY.YYY;
}
server {
        listen 6666 ssl;
        listen 7777 ssl;
        listen 8888 ssl;
        listen 9999 ssl;

        server_name abc.def.ghi abc;
        location / {
                proxy_pass https://backend:$PORT;
        }
}

upstream backend {
        server XXX.XXX.XXX.XXX:$PORT;
        server YYY.YYY.YYY.YYY:$PORT;
}
server {
        listen 6666 ssl;
        listen 7777 ssl;
        listen 8888 ssl;
        listen 9999 ssl;

        server_name abc.def.ghi abc;
        location / {
                proxy_pass https://backend;
        }
}

我已经阅读并尝试了$ server_port,map和其他东西,但没有成功。

感谢您的时间

相关文章: NGINX using $server_port in upstream

0 个答案:

没有答案