Nginx代理,根据路径命中多个主机

问题描述 投票:0回答:0

要求是根据请求路径命中端点,例如,如果它的 /bsc 请求应该转到这两个,对于其他路径也类似,以下是我所拥有的工作

upstream bsc_backend {
    least_conn;
    server bsc-mainnet.gateway.network:443;
    server nd-744-07-279.com:443 backup;
}

upstream eth_backend {
    least_conn;
    server nd-860-422-720.com:443;
    server eth-mainnet.gateway.network:443 backup;
}

server {
    listen       80;
    listen  [::]:80;
    server_name  localhost;

    location /proxy/bsc {
        proxy_set_header Host bsc-mainnet.gateway.network:443;
        proxy_pass https://bsc_backend/v1/lb/62cffbe1b37b8e00392b3872;
        proxy_ssl_server_name on;
        proxy_ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
        proxy_ssl_verify off;
    }

    location /proxy/eth {
        proxy_set_header Host nd-860-422-720.com:443;
        proxy_pass https://eth_backend/df11e01c3738cc840cc407a78131d596;
        proxy_ssl_server_name on;
        proxy_ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
        proxy_ssl_verify off;
    }
}

这里硬编码的两个问题,一个是 proxy_set_header,我已经尝试了所有内部变量,如 $host、$upstream_addr $upstream__host_addr,其中一些是空的,一些返回的是 IP 地址而不是域名

第二个问题是删除路径中的硬编码,该硬编码根据当前活动的上游而变化。

请通过一些意见,我正在努力。如果我应该使用其他东西而不是 nginx,请告诉我。

谢谢

nginx nginx-reverse-proxy nginx-config nginx-location
© www.soinside.com 2019 - 2024. All rights reserved.