我需要在端口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.ioHTTPS网站运行良好,尽管我收到了http 404错误。我想问题出在重写Cond上。
websocket.js:112WebSocket连接到'wss://mysite.com/socket.io/?id=11518237&username=john失败:错误在WebSocket握手期间:意外的响应代码:404
尝试mod_proxy_stunnel
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
为不同的用途使用不同的IP地址。您有<VirtualHost *:443>
,它尝试使用单个虚拟主机的所有IP地址。我想您需要一个用于Let's Encrypt的<VirtualHost pub.lic.ip.addr:443>
和用于socket.io代理的<VirtualHost localhost:443>
。