【问题标题】:How to use RewriteRule and ProxyPass to get conditional proxying?如何使用 RewriteRule 和 ProxyPass 获得条件代理?
【发布时间】:2019-07-05 14:58:44
【问题描述】:

我想要做的是将每个 websocket 初始化代理到 "ws://localhost:8081" 并将其余流量直接代理到 http://localhost:80801

我使用[P] 标志让它工作,但是不鼓励这样做,因为它不使用连接池。

想法是如果设置了标头,则将请求重写为/websocket,然后如果url是/websocket,则proxypass到ws端点。

但是,这不适用于 WS(适用于 http)

#rewrite for websockets

RewriteEngine On
LogLevel alert rewrite:trace8
RewriteCond "%{HTTP:Upgrade}" "websocket"
# RewriteRule "" "ws://localhost:8081" [P] works via proxy like that 
RewriteRule "" "/websocket" [L]

ProxyPass /websocket "ws://localhost:8081"
ProxyPassReverse /websocket "ws://localhost:8081"

ProxyPass / http://localhost:8081/

我做错了什么?

【问题讨论】:

    标签: apache httpd.conf


    【解决方案1】:

    大约 10 秒后,我得到了答案。

    我必须通过请求,所以像

    这样的设置
    RewriteCond "%{HTTP:Upgrade}" "websocket"
    # RewriteRule "" "ws://localhost:8081" [P] works via proxy like that 
    RewriteRule "" "/websocket" [L,PT]
    

    完成这项工作。

    【讨论】:

      猜你喜欢
      • 2010-10-27
      • 2019-01-25
      • 1970-01-01
      • 1970-01-01
      • 2018-10-18
      • 2021-02-27
      • 2013-06-06
      • 2020-06-29
      • 1970-01-01
      相关资源
      最近更新 更多