nginx中proxy_pass末尾的/

http://tomcatserver;和http://tomcatserver/;有什么区别呢?

location /service/ {
proxy_pass http://tomcatserver;
proxy_next_upstream error timeout invalid_header http_500 http_503 http_404;
}

location /service/ {
proxy_pass http://tomcatserver/;
proxy_next_upstream error timeout invalid_header http_500 http_503 http_404;
}
同样访问:http://xymiao.com/service/add.php
前者配置,在后端的机器,收到的是http://xymiao.com/service/add.php
后者配置,在后端的机器,收到的是http://xymiao.com/add.php

如果换成下面这样,会报错:
location ~ ^/(service)/ {
proxy_pass http://tomcatserver/;
proxy_next_upstream error timeout invalid_header http_500 http_503 http_404;
}
“proxy_pass” may not have URI part in location given by regular expression, or inside named location, or inside the “if” statement, or inside the “limit_except” block in nginx.conf:

但是,这样就没问题了:
location ~ ^/(service)/ {
proxy_pass http://tomcatserver;
proxy_next_upstream error timeout invalid_header http_500 http_503 http_404;
}

如有帮助, 可以支持一下
分享到:

发表评论

昵称

沙发空缺中,还不快抢~