Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Meteor, WebSocket, Nginx 502 Error

We are trying to run a Meteor application on a Debian server behind Nginx. The application is running but GET requests at http://url/sockjs?info?cb=[random_string] returns 502 Bad Gateway.

The Nginx configuration is set up as thus:

# this section is needed to proxy web-socket connections
map $http_upgrade $connection_upgrade {
    default upgrade;
    ''      close;
}

upstream app_server {
    server 127.0.0.1:3000; # for a web port socket (we'll use this first)
    # server unix:/var/run/app/app.sock;
}

server {
    listen       80;
    server_name  app_server.com;

    charset utf-8;
    client_max_body_size 75M;

    access_log  /var/log/nginx/app.access.log;
    error_log  /var/log/nginx/app.error.log;

    location / {
        proxy_pass http://app_server;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;
        proxy_set_header X-Forwarded-For $remote_addr; # preserve client IP
        proxy_read_timeout 60s;
        keepalive_timeout 65;
        proxy_redirect off;
        # the root path (/) MUST NOT be cached
        if ($uri != '/') {
            expires 30d;
        }
    }
}

We have tried various configurations and could not figure out where the fault lies. Solution at Meteor WebSocket handshake error 400 with nginx didn't work either.

Edit: Tried following configuration found at recommended nginx configuration for meteor and it was still returning 502.

Edit: The application works fine when not obtaining images from Meteor CFS, which is used to store uploaded images via an admin dashboard. When loading images, a POST to domain/sockjs/img_location/cb/xhr_send causes a 502 error.

like image 352
mrkre Avatar asked Dec 09 '15 13:12

mrkre


1 Answers

Are you sure the issue is really coming from NGINX and websocket?

  • First you can try wcat as a websocket CLI to ensure if the websockets are working
  • You can also try to run the app in a console or look at the log (debug / verbose at max level) to see if there is not an underlying error
like image 98
samidarko Avatar answered Oct 01 '22 09:10

samidarko