I currently have a digital ocean droplet connected to a domain. On the server, I'm running NGINX and trying to reverse proxy multiple node apps to it. Currently, my root directory has one node express app, at location / .
I'm trying to connect another node express application, to another sub directory. Here's the nginx config file:
server {
listen 80;
server_name servername.com;
# my root app
location / {
proxy_pass http://127.0.0.1:6001;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
# new app
location ~^ /newapp {
proxy_pass http://127.0.0.1:6002;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
The problem is that the new app is trying to serve files out of /newapp, which is breaking. I'm thinking it's probably something in my app.js file to play around with Express in the new app, to set the base directory as /newapp/ - to serve both static files and routes from there. Any ideas on how to do this?
In the newapp, I'm serving static files as such:
// Serve files out of ./public
app.use(express.static(__dirname + '/public'));
and have route files as:
var index = require('./routes/index');
app.use('/', index);
with index routing file:
var express = require('express');
var router = express.Router();
// Get index page
router.get('/', function(req, res, next) {
res.render('index', {
index : 'active'
});
});
module.exports = router;