使用proxy_pass配置反向代理,在匹配到location配置的URL路徑后颈娜,轉(zhuǎn)發(fā)請(qǐng)求到proxy_pass配置額URL,是否會(huì)附加location配置路徑與proxy_pass配置的路徑后是否有"/"有關(guān),有"/"則不附加
location /test/ {
proxy_pass http://127.0.0.1:8080/;
}
請(qǐng)求/test/1.jpg内贮,將會(huì)被nginx轉(zhuǎn)發(fā)請(qǐng)求到http://127.0.0.1:8080/1.jpg(未附加/test/路徑)宣赔。
第一種
We're sorry but xxx doesn't work properly without JavaScript enabled.
出現(xiàn)這種錯(cuò)誤一般是反向代理配置錯(cuò)誤,檢查項(xiàng)目代碼配置文件和接口地址反向代理是否正確,檢查nginx反向代理是否配置正確
location /api {
// 如果接口訪問(wèn)一直為404,但服務(wù)并沒(méi)有問(wèn)題,考慮重寫(xiě)api/路徑之前的所有字符串為代理地址
rewrite ^.+api/?(.*)$ /$1 break;
proxy_pass http://localhost:9901/;
}
第二種 接口訪問(wèn)404
第一種寫(xiě)法
// 第一種寫(xiě)法
location ^~/ball/ {
try_files $uri $uri/ /ball/index.html;
index /ball/index.html
}
location /api {
// 如果接口訪問(wèn)一直為404,但服務(wù)并沒(méi)有問(wèn)題,考慮重寫(xiě)api/路徑之前的所有字符串為代理地址
rewrite ^.+api/?(.*)$ /$1 break;
proxy_pass http://localhost:9901/;
}
第二種寫(xiě)法
// 第二種寫(xiě)法
location /app1 {
# 瀏覽器訪問(wèn)地址,指向項(xiàng)目文件夾下的index.html
root html/app1;
index index.html index.htm;
}
# 配置反向代理,解決跨域問(wèn)題
location /api {
proxy_pass http://172.xx.xx.xx:8000;
}