Proxy websocket wss:// to ws:// apache

后端 未结 6 742
自闭症患者
自闭症患者 2021-02-02 02:15

i searched alot but i couldnt connect my websocket to wss:// , i found that there is a way to proxy wss://domain.com:9090 and apache apply the proxy on it and redirect request

6条回答
  •  梦毁少年i
    2021-02-02 02:40

    You need to enable some Apache2 modules:

    $ a2enmod proxy proxy_wstunnel proxy_http rewrite
    

    Then you can use this configuration to solve your problem.

        ProxyRequests off
        ProxyVia on      
        RewriteEngine On
    
        RewriteEngine On
        RewriteCond %{HTTP:Connection} Upgrade [NC]
        RewriteCond %{HTTP:Upgrade} websocket [NC]
        RewriteRule /(.*) ws://example.com:9090/$1 [P,L]
    
        ProxyPass               /websocket http://example.com:9090/websocket
        ProxyPassReverse        /websocket http://example.com:9090/websocket
    

    Apache2 automatically upgrades the connection to websocket with ws://, you don't need to set the ws:// manually. I tried dozens of configurations and this is the only one that worked for me.

提交回复
热议问题