There are several requirements:
- Setting Host header in nginx with desired domain or proxy, if applicable
- Use middleware subdomain before other intermediaries that process endpoints
Work example:
Nginx configuration :
server { listen 80; server_name bee.local; location / { proxy_pass http://127.0.0.1:3000; proxy_http_version 1.1; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; } } server { listen 80; server_name api.bee.local; location / { proxy_pass http://127.0.0.1:3000; proxy_http_version 1.1; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; } }
Nginx configuration with hard-coded host header values:
I believe that you have configured the node header incorrectly. try the following configuration
server { listen 80; server_name bee.local; location / { proxy_pass http://127.0.0.1:3000; proxy_http_version 1.1;
express application :
var subdomain = require('express-subdomain'); var express = require('express'); var app = express(); var router = express.Router(); router.get('/', function(req, res) { res.send('Welcome to our API!'); }); router.get('/users', function(req, res) { res.json([ { name: "Brian" } ]); }); app.use(subdomain('api', router)); app.get('/', function(req, res) { res.send('Homepage'); }); app.listen(3000);
valery.barysok
source share