简体   繁体   English

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

[英]How to run socket.io on port 443 where apache is running?

I need to run socket.io on port 443 (where apache run https site with Let's Encrypt) 我需要在端口443上运行socket.io(其中apache使用Let的加密运行https站点)

The idea is to use a apache proxy that will redirect the traffic to the socket.io port. 我们的想法是使用apache代理将流量重定向到socket.io端口。 I found that solution: 我找到了解决方案:

<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>

I run the socket.io on port 3999 HTTPS site works fine, howevever I got http 404 errors. 我在端口3999 HTTPS站点上运行socket.io工作正常,但我得到了http 404错误。 I guess problem is on rewriteCond. 我想问题是在rewriteCond上。

websocket.js:112 WebSocket connection to 'wss://mysite.com/socket.io/?id=11518237&username=john failed: Error during WebSocket handshake: Unexpected response code: 404 websocket.js:112 WebSocket连接到'wss://mysite.com/socket.io/?id = 11518237&username = john failed:WebSocket握手期间出错:意外响应代码:404

Use different IP addresses for the different uses. 为不同的用途使用不同的IP地址。 You have <VirtualHost *:443> which tries to use all IP addresses for the single virtual host. 您有<VirtualHost *:443> ,它尝试使用单个虚拟主机的所有IP地址。 I think you want a <VirtualHost pub.lic.ip.addr:443> for Let's Encrypt and a <VirtualHost localhost:443> for the socket.io proxy. 我想你想要一个用于Let的加密的<VirtualHost pub.lic.ip.addr:443>和一个用于socket.io代理的<VirtualHost localhost:443>

Try mod_proxy_wstunnel 尝试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 https://httpd.apache.org/docs/2.4/mod/mod_proxy_wstunnel.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM