我有一个基本的nginx设置,其中对example.com/xyz1的请求代理到127.0.0.1:9000,对example.com/xyz2的请求代理到127.0.0.1:9001。
在127.0.0.1:9000上运行一个快速服务器,它应该只服务静态文件。 对于我的index.html没有问题。但是无法解析所有依赖项,如css和JS文件。
const express = require('express');
const bodyParser= require('body-parser');
const app = express();
app.use(bodyParser.urlencoded({extended: true}));
app.use('/', express.static(__dirname + 'public'));
const MongoClient = require('mongodb').MongoClient;
MongoClient.connect("mongodb://localhost:27017/xyz1", (err, database) => {
if (err) return console.log(err);
db = database;
console.log('Connected to mongoDb');
app.listen(9000, () => {
console.log('Express-Server listening on port 9000');
})
})
app.get('/xyz1', (req, res) => {
console.log('xyz1');
res.sendFile(__dirname + '/public/' + 'index.html');
//res.send('Hello World xyz1');
})
我的xyz1文件夹结构:
如果有人需要查看nginx配置,请告诉我。