nginx 针对GET请求参数 反向代理到不同服务器【系统维护高手进】
时间:2015-04-22 22:45 来源:oschina.net 作者:IT
举个例子:
http://localhost/index.php?a=1
http://localhost/index.php?a=2
假设有这俩个请求,如何通过nginx配置能使得
a=1的请求 转到 http://localhost:8080
a=2的请求 转到 http://localhost:8081
求详细nginx 配置方法!系统维护的高手们帮忙解答下
http {
upstream server1 {
server 127.0.0.1:8080;
}
upstream server2 {
server 127.0.0.1:8081;
}
#...
server {
#...
set $backend_server "server1";
if ( $arg_a ~ '^1$' ) {
set $backend_server "server2";
}
location /index.php {
proxy_pass http://$backend_server;
}
}
}
关键点是$arg_X系列变量的使用,它就指代了querystring中对应变量X的值。
(责任编辑:IT)
举个例子: http://localhost/index.php?a=1 http://localhost/index.php?a=2 假设有这俩个请求,如何通过nginx配置能使得 a=1的请求 转到 http://localhost:8080 a=2的请求 转到 http://localhost:8081 求详细nginx 配置方法!系统维护的高手们帮忙解答下 http { upstream server1 { server 127.0.0.1:8080; } upstream server2 { server 127.0.0.1:8081; } #... server { #... set $backend_server "server1"; if ( $arg_a ~ '^1$' ) { set $backend_server "server2"; } location /index.php { proxy_pass http://$backend_server; } } } 关键点是$arg_X系列变量的使用,它就指代了querystring中对应变量X的值。 (责任编辑:IT) |