autobahn nginx load balancing issue with wss & externalPort option

#1

Hi,
I am using nginx to load balance autobahn websocket server using it as proxy server.How ever I get the following error in nginx error log
when I connect to proxy port using python websocket client. I have added externalPort in WebSocketServerFactory class.
Error I get in nginx error log:
__ 2015/09/09
15:15:01 [error] 24257#0: 127 upstream prematurely closed connection while reading response header from upstream, client: 127.0.0.1, server: ,
request: “GET /wronguri HTTP/1.1”, upstream: “http://127.0.0.1:9001/wronguri”, host: “127.0.0.1:9000”__ Autobahn
server is running on port 9001 and port 9000 is listening by nginx to redirect to web socket server. Below is my nginx configuration.
*
server {

 # your SSL configuration
listen 9000;
ssl on;
ssl_certificate /home/server.crt;
ssl_certificate_key /home/server.key;
location / {

proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host "loacalhost:9001";
    proxy_set_header X-NginX-Proxy true;
proxy_redirect off;
    # Handle Web Socket connections
  
    proxy_pass http://websocket;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";

}

}**

0 Likes

#2

I’ve been running nginx as an ssl layer to proxy websockets to my wamp application.

I don’t fully understand this config so I can’t give you reasons why yours does not work, but here is mine:

At the http level ( as a sibling to the server object ):

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

``

At the location level:

        proxy_http_version 1.1;
        proxy_redirect off;
        proxy_buffering off;
        proxy_connect_timeout 5;
        proxy_ignore_headers X-Accel-Expires Expires Cache-Control Set-Cookie X-Accel-Redirect X-Accel-Limit-Rate X-Accel-Buffering X-Accel-Charset;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-Host $host;
        proxy_pass_request_headers on;
        proxy_read_timeout 30;
        proxy_ssl_session_reuse off;

``

I’m pretty sure the proxy_set_header directives have very little to do with it. Also, the proxy_read_timeout may not be advisable, not sure. Hope this helps.

···

On Wednesday, September 9, 2015 at 3:14:21 AM UTC-7, Muhammed Irshad wrote:

Hi,
I am using nginx to load balance autobahn websocket server using it as proxy server.How ever I get the following error in nginx error log
when I connect to proxy port using python websocket client. I have added externalPort in WebSocketServerFactory class.
Error I get in nginx error log:
__ 2015/09/09
15:15:01 [error] 24257#0: 127 upstream prematurely closed connection while reading response header from upstream, client: 127.0.0.1, server: ,
request: “GET /wronguri HTTP/1.1”, upstream: “http://127.0.0.1:9001/wronguri”, host: “127.0.0.1:9000”__ Autobahn
server is running on port 9001 and port 9000 is listening by nginx to redirect to web socket server. Below is my nginx configuration.
*
server {

 # your SSL configuration
listen 9000;
ssl on;
ssl_certificate /home/server.crt;
ssl_certificate_key /home/server.key;
location / {

proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host "loacalhost:9001";
    proxy_set_header X-NginX-Proxy true;
proxy_redirect off;
    # Handle Web Socket connections
  
    proxy_pass [http://websocket](http://websocket);
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";

}

}**

0 Likes

#3

Correction, the Upgrade and Connection set_header directives are what tell Nginx to allow it to becomde a websockets connection. Besides those 2 directives, the other proxy_set_header lines are more cosmetic/informational.

···

On Wednesday, September 9, 2015 at 9:27:20 AM UTC-7, Mark Clifton wrote:

I’ve been running nginx as an ssl layer to proxy websockets to my wamp application.

I don’t fully understand this config so I can’t give you reasons why yours does not work, but here is mine:

At the http level ( as a sibling to the server object ):

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

``

At the location level:

        proxy_http_version 1.1;
        proxy_redirect off;
        proxy_buffering off;
        proxy_connect_timeout 5;
        proxy_ignore_headers X-Accel-Expires Expires Cache-Control Set-Cookie X-Accel-Redirect X-Accel-Limit-Rate X-Accel-Buffering X-Accel-Charset;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-Host $host;
        proxy_pass_request_headers on;
        proxy_read_timeout 30;
        proxy_ssl_session_reuse off;

``

I’m pretty sure the proxy_set_header directives have very little to do with it. Also, the proxy_read_timeout may not be advisable, not sure. Hope this helps.

On Wednesday, September 9, 2015 at 3:14:21 AM UTC-7, Muhammed Irshad wrote:

Hi,
I am using nginx to load balance autobahn websocket server using it as proxy server.How ever I get the following error in nginx error log
when I connect to proxy port using python websocket client. I have added externalPort in WebSocketServerFactory class.
Error I get in nginx error log:
__ 2015/09/09
15:15:01 [error] 24257#0: 127 upstream prematurely closed connection while reading response header from upstream, client: 127.0.0.1, server: ,
request: “GET /wronguri HTTP/1.1”, upstream: “http://127.0.0.1:9001/wronguri”, host: “127.0.0.1:9000”__ Autobahn
server is running on port 9001 and port 9000 is listening by nginx to redirect to web socket server. Below is my nginx configuration.
*
server {

 # your SSL configuration
listen 9000;
ssl on;
ssl_certificate /home/server.crt;
ssl_certificate_key /home/server.key;
location / {

proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host "loacalhost:9001";
    proxy_set_header X-NginX-Proxy true;
proxy_redirect off;
    # Handle Web Socket connections
  
    proxy_pass [http://websocket](http://websocket);
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";

}

}**

0 Likes