swoobie
swoobie

Reputation: 111

Nginx config for meteor

My question is how do I get Nginx to forward a domain (www.example.com) to a meteor app on the same server without ssl.

Here's the details: I'm trying to use Nginx to host an app made by meteor on my own server. I've checked a ton of different config files that I've found online (most of which are dated) but I can't seem to get Nginx to forward my domain name to port 3000 where meteor can pick it up and handle the web page.

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

upstream default {
        server 127.0.0.1:3000;
}

server {
        listen 80;
        server_name localhost;

        location / {
                proxy_pass http://default/;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection "upgrade";
                proxy_set_header Host $http_host;

                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forward-For $proxy_add_x_forwarded_for;
                proxy_set_header X-Forward-Proto http;
                proxy_set_header X-Nginx-Proxy true;

                proxy_redirect off;
        }
}

I've slightly modified it to what I believe is correct for my setup. I'm using the default config file in Nginx and I have created a meteor app in /usr/share/nginx/html using "meteor create html."

I know it's bad habit to use the defaults for all this but I'm just trying to get a meteor app up and running first.

I should have all the dependencies installed: meteor, nodejs, mongodb, and nginx.

A lot of the more up to date nginx configs I've found are using SSL which I don't intend to use. I'm not sure how to modify them for what I need either.

Could someone explain either why this config doesn't work or what I'm missing to get Nginx to point to my meteor app at www.example.com:3000?

Thanks in advance.

P.S.

I've been able to get the same setup working using a VM, with the exact same config file. I'm at a loss as to where I'm missing a step.

Upvotes: 4

Views: 1698

Answers (1)

swoobie
swoobie

Reputation: 111

The problem was a trailing backslash in the proxy_pass directive. It should've been proxy_pass http://default;. Thanks to anatoly for pointing that out.

UPDATE: Nginx documentation is a bit confused, but highlights the difference between proxy_pass with/without URI:

A request URI is passed to the server as follows:

If the proxy_pass directive is specified with a URI, then when a request is passed to the server, the part of a normalized request URI matching the location is replaced by a URI specified in the directive:

location /name/ {
    proxy_pass http://127.0.0.1/remote/;
}

If proxy_pass is specified without a URI, the request URI is passed to the server in the same form as sent by a client when the original request is processed, or the full normalized request URI is passed when processing the changed URI:

location /some/path/ {
    proxy_pass http://127.0.0.1;
}

Upvotes: 2

Related Questions