Node.js 在nginx服务器上部署nodejs项目

Node.js 在nginx服务器上部署nodejs项目,node.js,angular,express,nginx,nginx-location,Node.js,Angular,Express,Nginx,Nginx Location,我搜索了整个互联网,找不到任何答案。 我刚刚启动了自己的nginx服务器,正在部署一个nodejs项目,其中我使用的是angular4和expressjs。当我在nginx中使用位置“/”时,它工作正常,但当我更改为“/dbproject”时,它就不工作了 首先,它没有在我的公用文件夹中找到.js文件,但当我使用ng build--deploy url=/dbproject构建angular时,它找到了它,但随后出现了错误: Uncaught SyntaxError: Unexpected to

我搜索了整个互联网,找不到任何答案。 我刚刚启动了自己的nginx服务器,正在部署一个nodejs项目,其中我使用的是angular4和expressjs。当我在nginx中使用位置“/”时,它工作正常,但当我更改为“/dbproject”时,它就不工作了

首先,它没有在我的公用文件夹中找到.js文件,但当我使用ng build--deploy url=/dbproject构建angular时,它找到了它,但随后出现了错误:

Uncaught SyntaxError: Unexpected token <
polyfills.bundle.js:1 Uncaught SyntaxError: Unexpected token <
styles.bundle.js:1 Uncaught SyntaxError: Unexpected token <
vendor.bundle.js:1 Uncaught SyntaxError: Unexpected token <
main.bundle.js:1 Uncaught SyntaxError: Unexpected token < .
以下是app.js文件:

const express = require('express');
const path = require('path');
const bodyParser = require('body-parser');
const cors = require('cors');
const passport = require('passport');
const db = require('./config/db');
const app = express();

const users = require('./routes/users');
db.connect(db.MODE_PRODUCTION, function(err) {
  if (err) {
    console.log('Unable to connect to MySQL.')
    process.exit(1)
  } else {
    console.log("Connectad");
  }
});

// Port Number
const port = 3000;

// CORS Middleware
app.use(cors());

// Set Static Folder
app.use(express.static(path.join(__dirname, 'public')));


// Body Parser Middleware
app.use(bodyParser.json());

// Passport Middleware
app.use(passport.initialize());
app.use(passport.session());

require('./config/passport')(passport);

app.use('/users', users);

// Index Route
app.get('/', (req, res) => {
  res.send('Invalid Endpoint');
});


app.get('*', (req, res) =>{
  res.sendFile(path.join(__dirname, 'public/index.html'));
});
// Start Server
app.listen(port, () => {
  console.log('Server started on port '+port);
});
问题解决了

之前:

location /dbproject {
    proxy_pass http://localhost:3000;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_set_header Host $host;
    proxy_cache_bypass $http_upgrade;
}
之后:

location /dbproject {
    proxy_pass http://localhost:3000/;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_set_header Host $host;
    proxy_cache_bypass $http_upgrade;
}
问题解决了

之前:

location /dbproject {
    proxy_pass http://localhost:3000;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_set_header Host $host;
    proxy_cache_bypass $http_upgrade;
}
之后:

location /dbproject {
    proxy_pass http://localhost:3000/;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_set_header Host $host;
    proxy_cache_bypass $http_upgrade;
}

你能发布你的整个nginx站点设置吗?在你的配置中,
/dbproject/index.html
http://localhost:3000/dbproject/index.html
我应该如何解决这个问题?如果使用ng build--base href=/dbproject怎么办?那么它找不到.js文件:index.html:18 GET net::ERR_ABORTED index.html:18 GET net::ERR_ABORTED index.html:18 GET net::ERR_ABORTED index.html:18 GET net::ERR_ABORTED index.html:18 GETnet::ERR_ABORTED index.html:18 GET 404(未找到)您可以发布整个nginx站点设置吗?在您的配置中,
/dbproject/index.html
http://localhost:3000/dbproject/index.html
我应该如何解决这个问题?如果使用ng build--base href=/dbproject怎么办?那么它找不到.js文件:index.html:18 GET net::ERR_ABORTED index.html:18 GET net::ERR_ABORTED index.html:18 GET net::ERR_ABORTED index.html:18 GET net::ERR_ABORTED index.html:18 GETnet::ERR_ABORTED index.html:18 GET 404(未找到)您的前后文件相同…您的前后文件相同。。。