简体   繁体   中英

How to proxy WSS to WS with .htaccess

I'm trying to connect to a websocket server that is not WSS over HTTPS. For that, I'm trying to proxy the WSS to WS using apache config.

I've tried using ProxyPass but I only have access to the .htaccess file. So I've also tried using mod_rewrite with a [P] flag, but still no luck.

this is what my .htaccess file looks like right now :

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.

Your RewriteCond matches Upgrade: WebSocket case-sensitively, but (for example) Chrome sends 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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