Closed magestican closed 7 years ago
In the client side
var socket = io(http, {transports: ['polling','websocket']});
may be the problem is this: in their proxy is allowed *.example.com:80 and your socket is running in example.com:5000 , why not you create inverse proxy (using nginx) for using something like realtime.example.com https://www.nginx.com/blog/nginx-nodejs-websockets-socketio/
That issue was closed automatically. Please check if your issue is fixed with the latest release, and reopen if needed (with a fiddle reproducing the issue if possible).
I've been spending a whole night to solve this problem when I start to use https
or wss
or ssl
. It always says connection stopped before establish
with 400
error code.
Just a minutes ago, I found a solution for that:
At the SSL/TLS tab:
If you have your own cert
or SSL
or HTTPS
: set it to Full
. (The following 123 steps assume you have your own https certification)
If you only have an http server
: set it to Flexible
. (The Cloudflare will add https
or ssl
to your website automatically.)
After that, go to DNS tab, set Proxied
.
If you are not sure what you are doing, just go to DNS tab, set
DNS only
server {
listen 80;
server_name ai-tools-online.xyz;
return 301 https://ai-tools-online.xyz$request_uri;
}
server {
listen 443 ssl http2;
ssl_certificate /data/v2ray.crt;
ssl_certificate_key /data/v2ray.key;
ssl_protocols TLSv1.2 TLSv1.3;
#ssl_ciphers 3DES:RSA+3DES:!MD5;
server_name ai-tools-online.xyz;
location / {
proxy_pass http://127.0.0.1:5000;
}
location /socket.io {
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:5000/socket.io;
}
}
ai-tools-online.xyz
is your domain, http://127.0.0.1:5000
is your socket server.
Cross-Origin Controls
is set to '*'
to allow Cross-Origin Access
For flask-socketio
, is to use flask_socketio.SocketIO(app, cors_allowed_origins = '*')
systemctl restart nginx
caddy
, see the following links:https://github.com/yingshaoxo/Web-Math-Chat#reverse-proxy-configuration-for-https https://caddy.community/t/using-caddy-0-9-1-with-socket-io-and-flask-socket-io/508/6 https://www.nginx.com/blog/nginx-nodejs-websockets-socketio/
I have an issue were the proxy of on of my clients is negating wss requests, but the fall-back mechanism of socket.io doesnt take place if this is the case, specifically on a 400 bad request returned code from the server, can you look into it?