在 80 端口(testsite)上有一个 nginx 服务器,在 81 端口(test_vue)有一个 webpack 开发服务器,有一个 vue 应用程序。我做了代理,但是当我去 testsite/test_vue 时,控制台中会出现https://testsite/js/app.js net::ERR_ABORTED 404 (Not Found)。请告诉我我的不能在哪里。
//sites-availeble/testsite.conf
location /vue_test/ {
proxy_pass http://localhost:8081/;
proxy_redirect off;
client_max_body_size 4m;
}
location /dist/ {
proxy_pass http://localhost:8081/dist/;
proxy_redirect off;
client_max_body_size 4m;
}
//vue.config.js
module.exports = {
devServer: {
disableHostCheck: true
}
}
我不知道你到底出了什么问题,因为你需要查看 nginx 和 webpack 的完整配置,但是一切都对我有用,没有任何特殊技巧,只在 nginx 上,不影响其他任何东西。
代理服务器配置如下:
也许您的问题是缺少标题。您可以在官方文档中阅读有关 WebSocket 代理的信息。
/vue_test/url 的开头被代理到测试服务器?而 webpack 经常会生成带有绝对路径的 lib 路径。设置为测试配置 baseUrl/publicPath https://cli.vuejs.org/config/#publicpath
最后删除
/代理,以便到达服务器的完整路径。