Getting a 400 handshake error on POST requests to my Flask app running socket.io, but I've added in the configs for NGINX according to docs and posts I read online. I'm using an Application Load Balancer in AWS and have set a :80 Target Group and a :443 listener which forwards to the Target Group. I have also added a rule for the route /socket.io to forward request to the target group on :80 and have enabled sticky sessions within the target group. I'm also using a Route53 domain name and enforcing SSL everything works fine except the socket communication.
NGINX conf file:
server {
listen [::]:80;
listen 80;
server_name _domain_name_;
access_log /var/log/nginx/access.log;
location / {
proxy_pass http://127.0.0.1:8000;
include proxy_params;
}
location /socket.io {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
include proxy_params;
proxy_http_version 1.1;
proxy_buffering off;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_pass http://127.0.0.1:8000/socket.io;
}
}
And js file connection for socket.io:
var socket = io();
socket.on('connect', () => {
console.log(socket.connected); // true
});
Connection returns true.
UPDATE
Switched to NLB and am still having the same issues, however now on my NGINX logs I am seeing
connect() failed (111: Connection refused) while connecting to upstream
request: "GET /socket.io/?EIO=3&transport=polling&t=MvDPJhb HTTP/1.1",
upstream: "http://127.0.0.1:8000/socket.io/?
EIO=3&transport=polling&t=MvDPJhb"