项目场景:
nginx配置反向代理路径
问题描述
在配置nginx反向代理的过程中,路径可以匹配上但是一直报404,找不到路径。nginx配置如下:
location /business {
add_header Access-Control-Allow-Origin 'http://localhost:8080' always;
if ($request_method = 'OPTIONS') {
add_header Access-Control-Allow-Origin 'http://localhost:8080';
add_header Access-Control-Allow-Headers 'token';
return 204;
}
proxy_pass http://127.0.0.1:8003;
}
请求路径如下:
http://localhost/business/position/list
原因分析:
找了半天,最后发现是 proxy_pass 后面的路径 少写了一个正斜杠
解决方案:
改为下面这个就行了:
location /business {
add_header Access-Control-Allow-Origin 'http://localhost:8080' always;
if ($request_method = 'OPTIONS') {
add_header Access-Control-Allow-Origin 'http://localhost:8080';
add_header Access-Control-Allow-Headers 'token';
return 204;
}
proxy_pass http://127.0.0.1:8003/;
}