upstream apache {
server 127.0.0.1:8080;
}
server{
location ~* ^/service/(.*)$ {
proxy_pass http://apache/$1;
proxy_redirect off;
}
}
上面的代码片段会将url包含字符串"service“的请求重定向到另一个服务器,但不包含查询参数。
发布于 2013-07-25 21:48:28
我使用~
而不是~*
对kolbyjack的第二种方法进行了略微修改。
location ~ ^/service/ {
proxy_pass http://apache/$uri$is_args$args;
}
发布于 2016-05-24 15:30:40
您必须使用重写来使用proxy_pass传递参数。下面是我为s3部署angularjs应用程序所做的示例
S3 Static Website Hosting Route All Paths to Index.html
适应你的需求将会是这样的
location /service/ {
rewrite ^\/service\/(.*) /$1 break;
proxy_pass http://apache;
}
如果你想在http://127.0.0.1:8080/query/params/中结束
如果你想在http://127.0.0.1:8080/service/query/params/中结束,你需要类似这样的东西
location /service/ {
rewrite ^\/(.*) /$1 break;
proxy_pass http://apache;
}
发布于 2015-09-25 05:09:53
我修改了@kolbyjack代码,使其适用于
http://website1/service
http://website1/service/
带参数
location ~ ^/service/?(.*) {
return 301 http://service_url/$1$is_args$args;
}
https://stackoverflow.com/questions/8130692
复制相似问题