Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
557 views
in Technique[技术] by (71.8m points)

Vue + Express 项目 部署至 Linux服务器后访问不到静态资源

vue.config.js 的设置:

最开始设置的是绝对路径,不行, 改成相对路径后也还是不行。

module.exports = {
    publicPath: './',
}

Node Express :

// history 中间件
const history = require('connect-history-api-fallback')
// 静态资源
const assets = __dirname + '/dist'
app.use(express.static(assets))
app.get('/', (req, res) => {
    res.sendFile(__dirname + '/index.html')
})

目录

image

Nginx 配置

server {
    listen 80;
    location / {
        proxy_pass http://0.0.0.0:8080;
    }
}

报错信息

访问服务器的时候能获取到页面的 title ,但是获取不到静态的资源。
image
image

在本地运行的时候没有问题, 但是部署到 Linux 服务器上就这样了,

大佬们救命!!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

app.use('/css', express.static(assets +'/css'));
app.use('/js', express.static(assets +'/js'));


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...