前后端分離中Nginx作為web前端容器,需要訪問后端介面通常需要通過路徑轉發,直接訪問后端API會造成跨域問題,組態檔如下
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
location ^~ /app/ {
proxy_pass http://localhost:8081/;
}
其中埠80,訪問根路徑 http://localhost/ 則為 nginx容器本身內容,如訪問 http://localhost/app/ 將會跨域轉發至http://localhost:8081/ 目錄下 ,即訪問
http://localhost/app/api/test 實為 http://localhost:8081/api/test ,
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/12558.html
標籤:架構設計
上一篇:常用介面分類與模塊設計的方法
下一篇:大話設計-模板方法模式
