0

I am attempting to deploy a meteor app to my production server, running on Ununtu 14.04 and I am getting the following error in my log file (/var/log/nginx/error.log)

2014/12/02 16:03:38 [error] 19231#0: *4267 connect() failed (111: Connection refused) while connecting to upstream, client: 162.13.2.250, server: theserver.com, request: "GET /content/staticContent.json HTTP/1.1", upstream: "http://127.0.0.1:3000/content/staticContent.json", host: "theserver.com"

My app is fetching json content from 5 files and these are included as part of the project.

I have the following nginx configuration file. I am running nginx 1.6.2.

I should also note that visiting http://theserver.com/content/staticContent.json loads the content in my browser.

I have also run 'wget http://127.0.0.1:3000/content/staticContent.json' from the command line when logged into my production server and I can fetch the content.

server_tokens off;

upstream anna {
        server 127.0.0.1:3000;
}

# HTTP
server {
        listen 80;

        #server_name    *.theserver.com;
        server_name     theserver.com;

        location / {
                proxy_pass http://anna;
                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-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header X-Forward-Proto http;
                proxy_set_header X-NginX-Proxy true;

                proxy_redirect off;
        }
}

I also have the following upstart configuration file to run my Meteor App in a node fibre

description "Meteor.js (NodeJS) application for theserver.com"
author "Me <me@theserver.com>"

start on started mongodb and runlevel [2345]

stop on shutdown

respawn
respawn limit 10 5

setuid anna
setgid anna

script
        export PATH=/opt/local/bin:/opt/local/sbin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
        export NODE_PATH=/usr/lib/nodejs:/usr/lib/node_modules:/usr/share/javascript
        export PWD=/home/anna
        export HOME=/home/anna
        export BIND_IP=127.0.0.1
        export PORT=3000
        export HTTP_FORWARDED_COUNT=1
        export MONGO_URL=mongodb://localhost:27017/anna
        export ROOT_URL=http://theserver.com/
        exec node /home/anna/bundle/main.js >> /home/anna/anna.log
end script

My process for deployment is as follows:

  1. On my local machine I run 'meteor build .' and then scp that to my production server to the above home directory
  2. I then untar the .tar.gz file, cd into bundle/programs/server and run 'npm install'
  3. Finally, when logged in as 'anna' with sudo rights, I run 'sudo start anna' given the above upstart script
  4. On checking the generated log file, I see the generated html telling me there is a 502 bad gateway error.

When I go to the URL for the live website, I can see the loading icon I have put in place. This is the Meteor loading template I have put in place and I have configured IronRouter to use this as a loading template while it is waiting for the subscription to my collection to be filled, but this never happens because my server side mongodb instance never gets populated, for the reasons above.

Can anyone see anything unusual in the above that might be causing this 502 bad gateway error?

Running netstat -ln indicates to me that node.js is running, see below:

tcp        0      0 127.0.0.1:3000          0.0.0.0:*               LISTEN 

Thanks

matfin
  • 499
  • 4
  • 15

1 Answers1

0

Have you tried using meteor-up ? It handles the bundling and upstart config for you.

The suggested nginx config for meteor-up is below, it looks pretty similar to yours (taken from Using Meteor Up with NginX vhosts).

/etc/nginx/sites-enabled/mycustomappname.com.conf

server {
  listen                *:80;

  server_name           mycustomappname.com;

  access_log            /var/log/nginx/app.dev.access.log;
  error_log             /var/log/nginx/app.dev.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;
  }
}
cobberboy
  • 5,598
  • 2
  • 25
  • 22
  • Hi. Thanks for the suggestion. I had tried quite a few things to get this working and was never able to solve it. How I got around it was to create a new subdomain, directory on the server and nginx config file for loading static content. I then just dumped all my assets in there and it worked. Doing this is better practice, and it allowed me to free my code from all the content assets I had included. – matfin Jan 04 '15 at 01:18