如何在运行Apache的端口443上运行socket.io?

时间:2018-08-03 08:22:26

标签: apache websocket socket.io mod-proxy-wstunnel

我需要在端口443上运行socket.io(其中apache使用Let's Encrypt运行https网站)

这个想法是使用一个Apache代理,它将流量重定向到socket.io端口。 我找到了解决方法:

<VirtualHost *:443>
     ServerName mysite.com
     ServerAlias www.mysite.com

     SSLEngine on
     SSLProxyEngine On
     ProxyRequests Off

     SSLCertificateFile /etc/apache2/ssl/mysite.com.crt
     SSLCertificateKeyFile /etc/apache2/ssl/mysite.com.key
     SSLCertificateChainFile /etc/apache2/ssl/ca.cer

     DocumentRoot /var/www/errorPages

     ErrorDocument 503 /503.html
     ProxyPass /503.html !

     ProxyPass / http://localhost:3999/
     ProxyPassReverse / http://localhost:3999/

RewriteEngine on
RewriteCond %{HTTP:UPGRADE} ^WebSocket$ [NC]
RewriteCond %{HTTP:CONNECTION} ^Upgrade$ [NC]
RewriteRule .* ws://localhost:3999%{REQUEST_URI} [P]

</VirtualHost>

我在端口3999上运行socket.io HTTPS站点运行正常,但是出现了HTTP 404错误。 我猜问题出在rewriteCond上。

  

websocket.js:112 WebSocket连接到   'wss://mysite.com/socket.io/?id = 11518237&username = john失败:错误   WebSocket握手期间:意外的响应代码:404

2 个答案:

答案 0 :(得分:0)

将不同的IP地址用于不同的用途。您有<VirtualHost *:443>试图将所有IP地址用于单个虚拟主机。我认为您需要<VirtualHost pub.lic.ip.addr:443>进行加密,并使用<VirtualHost localhost:443>进行socket.io代理。

答案 1 :(得分:0)

尝试使用mod_proxy_wstunnel

It provides support for the tunnelling of web socket connections to a backend websockets server. The connection is automatically upgraded to a websocket connection

https://httpd.apache.org/docs/2.4/mod/mod_proxy_wstunnel.html

相关问题