1、項目中用到了代理,本地開發時沒問題,但是發布到服務器就404。
// config文件夾下面index.js文件
module.exports = {
dev: {
assetsSubDirectory: "static",
assetsPublicPath: "/",
proxyTable: {
"/api": {
target: 'http://www.test.com/', // 需要訪問的代理接口
changeOrigin: true,
pathRewrite: {
"^/api": "/"
}
}
},
host: 'localhost', // can be overwritten by process.env.HOST
port: 8001, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined
autoOpenBrowser: true,
errorOverlay: true,
notifyOnErrors: true,
poll: false, // https://webpack.js.org/configuration/dev-server/#devserver-watchoptions-
useEslint: true,
showEslintErrorsInOverlay: false,
devtool: "eval-source-map",
cacheBusting: true,
cssSourceMap: false
},
}
2、打包發布后需要在nginx配置文件中加入如下配置:
location /api{
rewrite ^.+api/?(.*)$ /$1 break; //可選參數,正則驗證地址
include uwsgi_params; //可選參數,uwsgi是服務器和服務端應用程序的通信協議,規定了怎么把請求轉發給應用程序和返回
proxy_pass http://www.test.com; // 接口地址
}