关于nginx:nginx反向代理404问题

2次阅读

共计 576 个字符,预计需要花费 2 分钟才能阅读完成。

在宝塔面板上配置 nginx 的反向代理时, 遇到 404 的问题, 经查资料, 找到解决方案, 这个问题个别是没有正确配置 proxy_pass. 集体比拟懒, 间接引知乎上的答复吧:

在 nginx 中配置 proxy_pass 反向代理时,当在前面的 url 加上了 /,相当于是相对根门路,则 nginx 不会把 location 中匹配的门路局部给代理走; 如果没有 /,则会把匹配的门路局部也给代理走。

例:

拜访门路:

/pss/bill.html
1. 当 nginx 配置文件 proxy_pass 后边的 url 带 ”/” 时:
location /pss/ {proxy_pass http://127.0.0.1:18081/;} 

代理到后端的门路为:http://127.0.0.1:18081/bill.html,省略了匹配到的 /pss/ 门路;

2. 当 nginx 配置文件 proxy_pass 后边的 url 不带 ”/” 时:
location /pss/ {proxy_pass http://127.0.0.1:18081;}

代理到后端的门路为:http://127.0.0.1:18081/pss/bill.html,连同匹配到的 /pss/ 门路,一起进行反向代理;

作者:韩玲
链接:https://www.zhihu.com/questio…
起源:知乎
著作权归作者所有。商业转载请分割作者取得受权,非商业转载请注明出处。

正文完
 0