4

My question is how do I get Nginx to forward a domain (www.example.com/app) to a meteor app on the same server. Nginx is running on port 80 and Meteor is running on port 4000 on the same machine.

Here are the details: I'm trying to use Nginx to host an app made by meteor on my own server. I can't seem to get Nginx to forward my domain name to port 4000 where meteor can pick it up and handle the web page.

The most recent config for Nginx to proxy a port is this:

server {
    listen 80 default_server;
    listen [::]: 80 default_server ipv6only = on;
    root /usr/share/nginx/html;
    index index.html index.htm;

    server_name localhost;

    location / {
        try_files $uri $uri / = 404;    
    }

    location /app {
        rewrite ^/app(.*) /$1 break;
        proxy_pass http://127.0.0.1:4000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header X-Forwarded-For $remote_addr;
   }
}

With this configuration when i access the meteor app at

www.example.com/app

all the *.js and *.css file requests are being forwarded to

www.example.com/xxxxxxxxxxxx.js

instead it should be as

www.example.com/app/xxxxxxxxxxxx.js

Could someone explain what I'm missing in Nginx configuration or Meteor configuration to point my meteor app at

www.example.com/app

Mark Stosberg
  • 12,961
  • 6
  • 44
  • 49
  • seems like there is similar SOF - http://stackoverflow.com/questions/32170123/mulitple-meteor-sites-behind-nginx – Samba Jan 20 '16 at 18:51
  • a lot great answer here: http://stackoverflow.com/questions/18003689/recommended-nginx-configuration-for-meteor –  Jan 22 '16 at 06:13

1 Answers1

0

Remove this line:

    rewrite ^/app(.*) /$1 break;

It's converting URLS like www.example.com/app/xxxxxxxxxxxx.js back to www.example.com/xxxxxxxxxxxx.js

Mark Stosberg
  • 12,961
  • 6
  • 44
  • 49
  • rewrite is required as meteor (or node.js) application serves requests from / not from '/app', so ngnix has to forward the requests to http://127.0.0.1:4000/ – Samba Jan 20 '16 at 15:49