bmullan91 / express-subdomain

Super simple subdomain middleware for expressjs
414 stars 49 forks source link

Nginx Issues #19

Closed dyaa closed 8 years ago

dyaa commented 8 years ago

Here's My nginx configuration

server {
  listen 80;
  server_name           ble.local;

  access_log            /var/log/nginx/ble.local.access.log;
  error_log             /var/log/nginx/ble.local.error.log;

  location / {
    proxy_pass http://127.0.0.1:3000;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_set_header X-Forwarded-For $remote_addr;
  }
}

server {
  listen 80;
  server_name           api.ble.local;

  access_log            /var/log/nginx/ble.local.access.log;
  error_log             /var/log/nginx/ble.local.error.log;

  location / {
    proxy_pass http://127.0.0.1:3000;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_set_header X-Forwarded-For $remote_addr;
  }
}

and here's my router with subdomain support

router.get('/v1/', function(req, res, next) {
    res.status(200).json({ title: makeid() });
});
app.use(subdomain('api', router));

The problem is that it's rendering the index route

and for sure i setup-ed the hosts file

I've been searching for 3 hrs can you help me :)

rusintez commented 8 years ago

something like

app.enable('trust proxy');
app.use(subdomain('api', router));

X-Forwarded-Host gives the content of the Host header the client sent to the proxy.

proxy_set_header X-Forwarded-Host $http_host;
proxy_set_header Host $http_host;
dyaa commented 8 years ago

Nothing changed do u have any imagination about how nginx configuration have to be !

bmullan91 commented 8 years ago

@dyaa I'm not much help to you I'm afraid. This isn't an issue with express-subdomain, and I've little knowledge of nginx.

First thing I'd try would be to replace proxy_pass http://127.0.0.1:3000; with the domains in your hosts file. For example, if your hosts file looks like this:

127.0.0.1 ble.local
127.0.0.1 api.ble.local

then try replacing proxy_pass http://127.0.0.1:3000; with proxy_pass http://api.ble.local:3000;