简体   繁体   English

如何使用.htaccess将WSS代理到WS

[英]How to proxy WSS to WS with .htaccess

I'm trying to connect to a websocket server that is not WSS over HTTPS. 我正在尝试通过HTTPS连接到不是WSS的websocket服务器。 For that, I'm trying to proxy the WSS to WS using apache config. 为此,我正在尝试使用apache config将WSS代理到WS。

I've tried using ProxyPass but I only have access to the .htaccess file. 我曾尝试使用ProxyPass,但只能访问.htaccess文件。 So I've also tried using mod_rewrite with a [P] flag, but still no luck. 因此,我也尝试将mod_rewrite与[P]标志一起使用,但还是没有运气。

this is what my .htaccess file looks like right now : 这是我的.htaccess文件现在的样子:

RewriteEngine On
RewriteCond %{HTTP:UPGRADE} ^WebSocket$
RewriteCond %{HTTP:CONNECTION} Upgrade$
RewriteRule /(.*) ws://127.0.0.1:9002/ [P]

However it doesn't seem to proxy because I still get a connection error from a wss connection. 但是它似乎没有代理,因为我仍然从wss连接中收到连接错误。

Your RewriteCond matches Upgrade: WebSocket case-sensitively, but (for example) Chrome sends Upgrade: websocket . 您的RewriteCond区分大小写匹配Upgrade: WebSocket ,但是(例如)Chrome发送Upgrade: websocket Try using case-insensitive rules : 尝试使用不区分大小写的规则

RewriteCond %{HTTP:Connection} Upgrade [NC]
RewriteCond %{HTTP:Upgrade} websocket [NC]
RewriteRule /(.*) ws://127.0.0.1:9002/$1  [P,L]

See also here: https://stackoverflow.com/a/29823699/200445 另请参阅此处: https : //stackoverflow.com/a/29823699/200445

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

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