vite.config配置
server: {
port: 9090,
cors: true, // 默认启用并允许任何源
open: true, // 在服务器启动时自动在浏览器中打开应用程序
//反向代理配置,注意rewrite写法
proxy: {
"/api": {
target: "http://xx.xx.xx.x1:8090", //代理接口
changeOrigin: true,
rewrite: (path) => path.replace(/^\/api/, "api"),
},
"/web": {
target: "http://xx.xx.xx.x2:8090", //代理接口
changeOrigin: true,
rewrite: (path) => path.replace(/^\/web/, "web"),
},
},
},
nginx配置:
location ^~ /api/ {
proxy_pass http://xx.xx.xx.x1:8090/api/; # 转发地址
}
location ^~ /web/ {
proxy_pass http://xx.xx.xx.x2:8090/web/; # 转发地址
}
vite.config.js与nginx配置代理
最新推荐文章于 2024-04-03 23:59:10 发布