[英]Meteor gets WebSocket error with Apache Proxy
我有一个通过Apache代理访问的Meteor应用程序。 该应用似乎可以运行,但我在Chrome控制台中看到错误。 我认为它之所以有效是因为存在一些不理想的回退。 它得到错误:
ddp-client failed: Error during WebSocket handshake: Unexpected response code: 400
我已经阅读了很多解决此问题的解决方案,这些解决方案似乎相当普遍(并尝试了很多),但是它们通常与复杂性联系在一起,这些复杂性使解决方案在我非常简单的设置中无法使用。 简而言之,我应该如何配置Apache代理服务Meteor并避免WebSocket ddp-client错误。
<VirtualHost *:80>
ServerName my-domain.com
????
</VirtualHost>
您的应用程序之所以能够正常工作,是因为Meteor在后台使用了SockJS进行了XHR长时间轮询。
要启用WebSocket代理,如果您使用的是Apache 2.4.5及更高版本,则可以尝试使用mod_proxy
和mod_proxy_wstunnel
(假设您的Meteor应用程序侦听端口3000):
<VirtualHost *:80>
ServerName my-domain.com
RewriteEngine On
RewriteCond %{QUERY_STRING} transport=websocket [NC]
RewriteRule /(.*) ws://localhost:3000/$1 [P,L]
ProxyPass / http://localhost:3000/
ProxyPassReverse / http://localhost:3000/
</VirtualHost>
在不使用上述模块的情况下,您可以尝试以下操作:
<VirtualHost *:80>
ServerName my-domain.com
RewriteEngine on
RewriteCond %{HTTP:UPGRADE} ^WebSocket$ [NC]
RewriteCond %{HTTP:CONNECTION} Upgrade$ [NC]
RewriteRule /(.*) ws://localhost:3000/$1 [P,L]
</VirtualHost>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.