Nginx 路径问题
location /protraceService/ {
#root html;
#index index.html index.htm;
proxy_pass http://localhost:8080/;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass_request_headers on;
}
location /protrace {
alias /home/product_trace/dist/;
index index.html;
try_files $uri $uri/ /index.html
add_header Pragma no-cache;
add_header Expires 0;
add_header Cache-Control no-cache,no-store,must-revalidate;
add_header Access-Control-Allow-Origin *;
proxy_intercept_errors on; #开启自定义错误页面
}
访问: www.example.com/protrace网站
场景1:
window.g = {
baseURL: './protraceService'
}
网站访问接口时会访问 www.example.com/protrace/protraceService/xxx
场景2:
window.g = {
baseURL: '/protraceService'
}
网站访问接口时会访问 www.example.com/protraceService/xxx
nginx 配置后台接口
location /protrace2/ {
proxy_pass http://localhost:8080/;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass_request_headers on;
}
# 至于为什么要在路径后面加要给'/',我也不清楚,反正加了对,不加错