http://localhost/service/image-------------> http://localhost:8080/service/image
http://localhost/service/image/upload------> http://localhost:8080/service/image/upload
http://localhost/service/blog--------------> http://localhost:8080/service/blog ..... .................................................. .................................................. .................................................. ........... 但是打击仍然会由ngnix服务,因为url中没有包含“服务”
怎么做?
答案 0 :(得分:0)
如果我理解正确的话:
location / {
if ($request_uri ~* "^/service/.*") {
rewrite ^ http://localhost:8080$request_uri permanent;
}
}
P.S。没检查
答案 1 :(得分:0)
您需要将位置正则表达式匹配与proxy_pass一起使用,例如:
upstream apache {
server 127.0.0.1:8080;
}
# in your server block:
server{
# location matching is prioritized by accuracy and order of definition
location ~* ^/service {
proxy_pass http://apache;
proxy_redirect off;
}
}
^/service
将匹配以/service
开头的任何请求,并将其转发给Apache。
proxy_pass
对用户是透明的,即它会将请求转发给Apache并将输出返回给用户。
有关位置匹配的详情,请结帐http://wiki.nginx.org/HttpCoreModule#location