Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nginx reverse proxy websocket, some connection disconnected with 1006 #725

Closed
weishuaiwang opened this issue Sep 26, 2021 · 2 comments
Closed
Labels

Comments

@weishuaiwang
Copy link

i debug websocket service with ip:port, it runs well, this is important.
but when i change to nginx for proxy websocket, it happens some connections just closed when request in (i watch the terminal),and the chrome,firefox console return readystate of 1006,but some other connected correctly.

here is my code:

nginx

map $http_upgrade $connection_upgrade {
     default upgrade;
     ''      close;
}

upstream websocket {
    server 172.17.0.1:9099 weight=5 max_fails=3 fail_timeout=30s;
    keepalive 16;
}

server {
    listen 80;
    server_name mysite.com;

    location /ws {
         try_files $uri $uri/ @workman;
    }

    location @workman {
        # proxy_set_header HTTPS "on";
        proxy_pass http://websocket;
        proxy_read_timeout 300s;
        proxy_send_timeout 300s;

        proxy_http_version 1.1;
        proxy_set_header Host $http_host;
        proxy_set_header Scheme $scheme;
        proxy_set_header SERVER_PORT $server_port;
        proxy_set_header REMOTE_ADDR $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;
        proxy_redirect off;
    }

    location / {
        proxy_pass http://websocket;
        proxy_connect_timeout 300s;

        proxy_set_header Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Scheme $scheme;
    }
}
@ghost
Copy link

ghost commented Sep 26, 2021

You will have more success finding out why connections are closed with nginx on an nginx specific forum or issue tracker.

@garyburd
Copy link
Contributor

This is a nginx issue per previous comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants