關(guān)于前后端分離解決跨域并實(shí)現(xiàn)nginx接口代理轉(zhuǎn)發(fā)配置

server {

listen? ? ? 80;

?server_name? ABC.com;

charset utf-8;

#access_log? logs/host.access.log? main;

location / {

try_files $uri $uri/ /index.html;#支持history模式刷新,解決前端history模式下,出現(xiàn)404

root? /home/WebServer/dist;

index? index.html index.htm;

}

location ^~ /apis/{#表示匹配apis

proxy_pass http://11.1.1.144:8080/;#后臺(tái)服務(wù),此處URL需要追加 “/” 轉(zhuǎn)發(fā)請(qǐng)求到后臺(tái)會(huì)去掉apis否則會(huì)保留apis

proxy_cookie_path / /;

proxy_set_header HOST $host;

proxy_set_header X-Real-IP $remote_addr;

#proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

proxy_set_header X-Forwarded-For $remote_addr;

#? proxy_cache_methods POST;

}

access_log /data/logs/nginx/ABC.com/access.log access;

error_log? /data/logs/nginx/ABC.com/error.log error;

}

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容