ryandotsmith / nginx-buildpack

Run NGINX in front of your app server on Heroku
457 stars 248 forks source link

websockets over nginx #66

Closed Flaminator89 closed 2 years ago

Flaminator89 commented 7 years ago

I've been using this package to proxy to a couple of different express servers without issue. However, I found that when I try and use a websockets server it is not working.

I'm using the default config with a few modifications...

daemon off;
#Heroku dynos have 4 cores.
worker_processes 4;

events {
    use epoll;
    accept_mutex on;
    worker_connections 1024;
}

http {
    gzip on;
    gzip_comp_level 2;
    gzip_min_length 512;

    log_format l2met 'measure.nginx.service=$request_time request_id=$http_heroku_request_id';
    access_log logs/nginx/access.log l2met;
    error_log logs/nginx/error.log;

    include mime.types;
    default_type application/octet-stream;
    sendfile on;

    map $http_upgrade $connection_upgrade {
        default upgrade;
    }

    server {
        listen <%= ENV["PORT"] %>;
        server_name _;
        keepalive_timeout 5;

        location /test {
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Host $http_host;
            proxy_redirect off;
            proxy_pass http://127.0.0.1:3000;
        }
        location / {
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Host $http_host;
            proxy_set_header X-NginX-Proxy true;

            proxy_buffers 8 32k;
            proxy_buffer_size 64k;

            proxy_pass http://127.0.0.1:3001;
            proxy_redirect off;
            proxy_ignore_client_abort on;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
        }
    }
}

I changed the part under default upgrade to not close on empty string, since this was causing issues. However, I still have an error once doing that which is:

2017/02/20 06: 6 connect() failed (111: Connection refused) while connecting to upstream, client: 10.186.58.177, server: _, request:"GET /?encoding=text HTTP/1.1", upstream: "http://127.0.0.1 :3001/?encoding=text", host: "www.mydomain.com"

My websocket server is listening on port 3001 as well, so I'm not sure what the issue is. Does this buildpack do anything different config wise, i.e. is there any reason why websockets shouldn't work over this buildpack?