Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

打包部署到服务器nginx后,访问后端接口404 #2788

Closed
zhangyu-yxff opened this issue Nov 26, 2019 · 8 comments
Closed

打包部署到服务器nginx后,访问后端接口404 #2788

zhangyu-yxff opened this issue Nov 26, 2019 · 8 comments

Comments

@zhangyu-yxff
Copy link

打包没问题,部署到服务器nginx后,主页可以正常访问,调用后端接口时报404并且提示:We're sorry but 网上报销系统 doesn't work properly without JavaScript enabled. Please enable it to continue.
修改了router的模式 history 还是不行 ,刚开始接触,麻烦大佬帮忙看看,多谢多谢~
publicPath: '/', outputDir: 'dist', assetsDir: 'static', lintOnSave: process.env.NODE_ENV === 'development', productionSourceMap: false, devServer: { port: port, open: false, overlay: { warnings: false, errors: true }, proxy: { // change xxx-api/login => mock/login // detail: https://cli.vuejs.org/config/#devserver-proxy [process.env.VUE_APP_BASE_API]: { ws: false, target:http://localhost:8090/`,
changeOrigin: true,
pathRewrite: {
['^' + process.env.VUE_APP_BASE_API]: ''
}
}
}
// after: require('./mock/mock-server.js')
},
configureWebpack: {
// provide the app's title in webpack's name field, so that
// it can be accessed in index.html to inject the correct title.
name: name,
resolve: {
alias: {
'@': resolve('src')
}
},`

@sunpu007
Copy link

sunpu007 commented Nov 26, 2019

用最新版本打包部署Nginx未发现你所遇到的问题,可以把url贴出来看看,这是我部署的地址http://test.myjerry.cn

@zhangyu-yxff
Copy link
Author

用最新版本打包部署Nginx未发现你所遇到的问题,可以把url贴出来看看,这是我部署的地址http://test.myjerry.cn

我这边调用了后端接口,本地run没有问题,麻烦发一下vue.config.js 和 nginx.conf 的 配置文件 是不是有什么地方没有修改

@zhangyu-yxff
Copy link
Author

用最新版本打包部署Nginx未发现你所遇到的问题,可以把url贴出来看看,这是我部署的地址http://test.myjerry.cn

image
这是我调用后端的配置,本地run是正常的 都部署在一台服务器上

@sunpu007
Copy link

根据你的描述,我暂判定你是自己写了一个服务端api,自己写的服务端api需要在Nginx上配置相应请求转发,类似这样
image

@zhangyu-yxff
Copy link
Author

根据你的描述,我暂判定你是自己写了一个服务端api,自己写的服务端api需要在Nginx上配置相应请求转发,类似这样
image

image
这是我目前nginx的配置

@sunpu007
Copy link

综上所述,你可以将你的配置改成如下:
image

@zhangyu-yxff
Copy link
Author

综上所述,你可以将你的配置改成如下:
image

好的 我试下 非常感谢~

@zhangyu-yxff
Copy link
Author

综上所述,你可以将你的配置改成如下:
image

参照这种方式,重新安装了一遍nginx,调试了半天,终于跑通,非常感谢~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants