最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Websocket failing on real domain - Stack Overflow

programmeradmin2浏览0评论

I am developing a turn-based game with websocket communication. It all works on localhost, and it actually worked on my previous domain on the same server I am at now. But now, when I changed domain, I suddenly started to get an error in the console: WebSocket connection ton'wss://example/socket.io/?EIO=4&transport=websocket' failed: createSocket @ index-WoxGCKpd.js:26....

I know there was lots of work back and forth with my openlitespeed.conf settings but I copied over what I had before to my new domain with the same server code. U have the following in my openlitespeed.conf, and the same for -443:

virtualHost example-80 {
ProxyPass / http://127.0.0.1:5000/
ProxyPassReverse / http://127.0.0.1:5000/
ProxyPass /socket.io/ ws://127.0.0.1:5000/socket.io/
ProxyPassReverse /socket.io/ ws://127.0.0.1:5000/socket.io/
  user                    admin
  ...
  #VirtualHost config settings
  ...
  rewrite  {
    enable                  1
    autoLoadHtaccess        1
    RewriteCond %{HTTP:X-Forwarded-Proto} https [NC]
    RewriteRule . - [E=HTTPS:on]
    RewriteCond %{HTTPS} !=on
    RewriteCond %{HTTP:X-Forwarded-Proto} !https [NC]
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    # Mail auto configuration (Thunderbird)
    RewriteRule ^/\.well-known/autoconfig/mail/config-v1\.1\.xml$ http://dainternal/$0 [P,L]
  }
  # include aliases
  include /usr/local/lsws/conf/httpd-alias.conf
  extprocessor nodejs{
type proxy
address 127.0.0.1:5000
maxConns 2000
initTimeout 20
retryTimeout 0
respBuffer 0
}
context / {
type proxy
handler nodejs
addDefaultCharset off
}
context /socket.io {
    type proxy
    handler nodejs
    location 127.0.0.1:5000
    allowBrowse 1
    addResponseHeader Connection "Upgrade, Keep-Alive"
    addResponseHeader Upgrade "websocket"
    proxySetHeader Upgrade $http_upgrade;
    proxySetHeader Connection "Upgrade";
    proxySetHeader Host $host;
    proxySetHeader X-Real-IP $remote_addr;
    proxySetHeader X-Forwarded-For $proxy_add_x_forwarded_for;
    proxySetHeader X-Forwarded-Proto $scheme;
    websocket 1
}
}

I tried a lot of different configurations but can't get the error to fix. What I fixed and tested so far:

  1. SSL on the domain which works
  2. Still works on localhost as normal
  3. Updated CORS settings to allow my origin for both localhost and example
  4. My host says there are no other settings to fix such as fire walls or opening of ports

I have no clue where to start looking, any ideas?

发布评论

评论列表(0)

  1. 暂无评论