spring websocket基於STOMP協議實現,apache httpd反向代理配置

最近打算正式使用websocket,須要作負載,而使用的是apache http server,搗騰了一天找到了一種比較靠譜的方式,特此記錄一下。web

加載的模塊以下:express

LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_connect_module modules/mod_proxy_connect.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_wstunnel_module modules/mod_proxy_wstunnel.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule rewrite_module modules/mod_rewrite.so
LoadModule proxy_express_module modules/mod_proxy_express.soapache

不排除有遺漏,由於我這邊所有加載的,只去除了幾個不須要的。websocket

 

conf/http.conf中須要加入或者刪除註釋:session

Include conf/extra/httpd-vhosts.conf

 

conf/extra/httpd-vhosts.conf配置:socket

<VirtualHost *:8088>

    ServerAdmin webmaster@dummy-host.bigdata.com
    ServerName localhost
    ErrorLog "logs/bigdata.com-error_log"

    CustomLog "logs/bigdata.com-access_log" common
     ProxyRequests Off
     Header add Set-Cookie "ROUTEID=.%{BALANCER_WORKER_ROUTE}e; path=/" env=BALANCER_ROUTE_CHANGED

# websocket
    RewriteEngine On 
    RewriteCond %{HTTP:Connection} Upgrade [NC]
    RewriteCond %{HTTP:Upgrade} websocket [NC]
    RewriteRule /(.*)           balancer://proxy2/$1 [P,QSA,L]

     Proxypass /bigdata balancer://proxy
        #stickysession=JSESSIONID|jsessionid nofailover=On
     ProxyPassReverse /bigdata balancer://proxy

     #ProxyPassReverseCookiePath /bigdata /bigdata

   <Proxy balancer://proxy2>
         Order Deny,Allow
         Allow from all
     
      RequestHeader set Connection "Upgrade"
      RequestHeader set Upgrade "websocket"   
      BalancerMember ws://10.214.136.181:8080 loadfactor=2 route=work89
      BalancerMember ws://10.214.136.180:8080 loadfactor=1 route=work90
      ProxySet stickysession=ROUTEID
     </Proxy>

     <Proxy balancer://proxy>
         Order Deny,Allow
         Allow from all
         BalancerMember http://10.214.136.180:8080/bigdata loadfactor=2 route=work89
         BalancerMember http://10.214.136.180:8080/bigdata loadfactor=1 route=work90
         ProxySet stickysession=ROUTEID
     </Proxy>

</VirtualHost>

根據頭信息是不是websocket來重寫url。url

相關文章
相關標籤/搜索