I am trying to run two express apps on the same server (one being a public API and the other being the private API that talks to the DB).
I have set up nginx to reverse proxy to my public express app that is running on port 3000, with a private IP from digital ocean.
My public express app sends requests to the private api (running on port 3030)
When I go to my domain example.com:3030/users - I can see all my users. (bad).
How can I lockdown port 3030 from the public (ie: website.com/:3030/API-ROUTE)?
nginx setup:
server {
listen 80;
server_name 123.456.78.910;
root /srv/www;
location / {
root /srv/www/public;
try_files $uri/maintenance.html @node_app;
}
location @node_app {
proxy_pass http://98.765.4.32:3000;
proxy_http_version 1.1;
proxy_set_header X-NginX-Proxy true;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
Public API
var express = require('express');
var app = express();
app.get('/', function (req, res) {
res.send('Hello public World!');
});
app.listen(3000, function () {
console.log('Example app listening on port 3000!');
});
Private API
var express = require('express');
var app = express();
app.get('/', function (req, res) {
res.send('Hello Private World!');
});
app.listen(3030, function () {
console.log('Example app listening on port 3030!');
});