Apache2反向代理和websocks

时间:2020-04-03 14:40:03

标签: apache websocket reverse-proxy

我正在尝试通过以下方式允许反向代理中的网络袜:

<Location "/monitor">
        ProxyPreserveHost On
        RequestHeader set X-Forwarded-Proto https
        RequestHeader set X-Forwarded-Port 443

        RewriteEngine On
        RewriteCond %{REQUEST_URI}  ^/monitor/notify       [NC]
        RewriteCond %{QUERY_STRING} transport=websocket    [NC]
        RewriteRule ^/monitor/notify/(.*) wss://localhost:8001/monitor/notify/$1         [P,L]

        ProxyPass http://localhost:8001/monitor
        ProxyPassReverse http://localhost:8001/monitor
</Location>

但是我遇到了这个错误:

VM690:149 WebSocket connection to 'wss://MY.HOST/monitor/notify/516/q7pqnqdz/websocket' failed: Error during WebSocket handshake: Unexpected response code: 400

我做错了什么?

1 个答案:

答案 0 :(得分:0)

已解决:

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