Nginx proxy_pass 基于 POST/GET/PUT/DELETE 参数

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

我正在尝试配置 nginx 根据请求中的 POST/GET/PUT/DELETE 参数执行

proxy_pass

我想要

proxy_pass
http://10.0.0.2:8000
(如果
live=1
)或到
http://10.0.0.2:8081
(如果
live=0
)。

我尝试使用

if ($arg_live = "1")
但它仅适用于 GET 请求。

谢谢,

佩德罗

nginx reverse-proxy
2个回答
0
投票

我建议你试试这个..

if ($request_method = 'POST') {
 #your_directives_here
}

0
投票
   if ($arg_live = "0"){
        rewrite ^ /live1 last;
    }
    if ($arg_live = "1") {
        rewrite ^ /live0 last;
    }
    location /live0/ {
        proxy_pass http://live0-server;
    }
    location /live1/ {
        proxy_pass http://live1-server;
    }
© www.soinside.com 2019 - 2024. All rights reserved.