# devServer.proxy 及 nginx 配置
# 1. 更换主机
场景:
/ims/basic
-->http://localhost:3000/ims/basic
webpack:
modules.exports = {
devServer: {
proxy: {
'/ims/basic': 'http://localhost:3000'
}
}
}
nginx:
location /ims/basic {
proxy_pass http://localhost:3000;
proxy_redirect off;
proxy_set_header Host $host;
}
# 2. 更换前缀
场景:
/ims/basic
-->http://localhost:3000/api/basic
webpack:
modules.exports = {
devServer: {
proxy: {
'/ims/basic': {
target: 'http://localhost:3000',
pathRewrite: { '^/ims/basic': '/api/basic' },
}
}
}
}
nginx:
location /ims/basic {
rewrite /ims/basic/(.*) /api/basic/$1 break;
proxy_pass http://localhost:3000;
proxy_redirect off;
proxy_set_header Host $host;
}
上一篇: 下一篇:
本章目录