-
問題
前端vue項(xiàng)目打包部署在nginx中摸航,后端打包部署在tomcat中,二者分離舅桩,有跨域問題忙厌。
-
分析
可以使用nginx的代理模塊處理跨域問題。本質(zhì)是前端直接請(qǐng)求nginx江咳,讓nginx把請(qǐng)求轉(zhuǎn)發(fā)到tomcat中逢净。
服務(wù)器信息
域名:http://test.jerry.com/
域名綁定的ip:http://10.250.115.210解決方案
只需要配置nginx的server的location指令中增加一行proxy_pass指令即可。配置如下:
server {
listen 80;
listen [::]:80;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/html/antifake;
index index.html index.htm;
}
location /login {
root /usr/share/nginx/html/antifake;
index index.html index.htm;
}
location /api {
proxy_pass http://10.250.115.210:8081; #只增加了這一行
}
重啟nginx歼指,應(yīng)用修改后的配置爹土。