Welcome! Log In Create A New Profile

Advanced

Reverse proxy'ing of socket.io events not working

Leonard Theivendra
June 03, 2019 02:56PM
Hi, I've been trying to get nginx reverse proxy'ing of socket.io events
working but not having any luck so would greatly appreciate any
help/insight. Basically my scenario is: nginx running in a docker container
(based on the nginx:stable-alpine image), a node server app serving up rest
APIs as well as responses via socket.io when those APIs are called. On the
client side, the aim is to call these APIs via the proxy, and also listen
to socket.io events return back through the proxy. And this is all ssl
secured.

My nginx conf file:

worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;

events {
worker_connections 1024;
}

http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log /var/log/nginx/access.log main;
sendfile on;
keepalive_timeout 65;

server {
listen 8080 ssl;

server_name localhost;

ssl_certificate /etc/nginx/conf.d/cert.pem;
ssl_certificate_key /etc/nginx/conf.d/key.pem;

location / {
proxy_pass https://apiandsocketservername:9091;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
}


My simple socket.io client node app:

socket = require('socket.io-client')(`https://localhost:8080`, {timeout:
5000, rejectUnauthorized: false});
// Connect to the socket
socket.on('connect', () => {
console.log('Connected to server');
});
// Wait on event named 'projectValidated'
socket.on('projectValidated', (args) => {
console.log('projectValidated');
console.log(args);
});


So the scenario would be to start up the node app above, then hit the rest
API endpoint on https://localhost:8080 via curl, and listen for the socket
event on https://localhost:8080 originating from
https://apiandsocketservername:9091 via the proxy.

When I run the nginx container and socket.io client locally on my laptop
everything works, and the nginx container logs has this added line when the
socket.io node app client connects, and no extra logging when the socket.io
events are successfully received:
172.17.0.1 - - [31/May/2019:16:31:07 +0000]
"GET /socket.io/?EIO=3&transport=polling&t=MiEkmaT&b64=1&sid=viHdGa9b26g9ejGYAAAD
HTTP/1.1" 200 3 "-" "nodeXMLHttpRequest" "-"
When I kill the socket.io client, nginx emits this single line in the log:
172.17.0.1 - - [31/May/2019:16:34:18 +0000]
"GET /socket.io/?EIO=3&transport=websocket&sid=viHdGa9b26g9ejGYAAAD
HTTP/1.1" 101 379 "-" "-" "-"


But when I run the same scenario on a kubernetes cluster where the nginx
proxy container and the socket.io client is on one pod and the rest api and
socket.io server is on a different pod: all the rest api proxy'ing works
for the both the https api calls and responses, and also the node app is
able to do the socket connection properly, but the socket.io event is never
received successfully. Nginx also continuously emits these two lines in the
log every 25 seconds:
9.37.248.25 - - [31/May/2019:17:37:26 +0000]
"GET /socket.io/?EIO=3&transport=polling&t=MiEzrxs&b64=1&sid=UJnUsScsSyJSmrOiAAAA
HTTP/1.1" 200 3 "-" "node-XMLHttpRequest" "-"
9.37.248.25 - - [31/May/2019:17:37:26 +0000]
"POST /socket.io/?EIO=3&transport=polling&t=MiEzy2V&b64=1&sid=UJnUsScsSyJSmrOiAAAA
HTTP/1.1" 200 2 "-" "node-XMLHttpRequest" "-"


Would anyone be able to shed light on what could be going wrong and if I
need to change anything in my nginx conf file? And what the above two lines
repeatedly emitted in the nginx log mean?

Thanks in advance,
Len.


---------------------------------------------
Len Theivendra
IBM Canada Software Lab
email: theivend@ca.ibm.com
tel: (905) 413-3777 tie: 969-3777
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

Reverse proxy'ing of socket.io events not working

Leonard Theivendra June 03, 2019 02:56PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 77
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready