Created
November 3, 2018 07:31
-
-
Save siutin/022e229b2b7cd0b3b0efebf564b8f825 to your computer and use it in GitHub Desktop.
Apache Websocket Proxy (socket.io) with Load Balancing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<VirtualHost *.:443> | |
ServerName whatever-domain.com | |
ErrorLog ${APACHE_LOG_DIR}/error.log | |
CustomLog ${APACHE_LOG_DIR}/access.log combined | |
SSLProxyEngine on | |
ProxyPreserveHost on | |
RewriteEngine On | |
Header add Set-Cookie "ROUTEID=.%{BALANCER_WORKER_ROUTE}e; path=/" env=BALANCER_ROUTE_CHANGED | |
<Proxy "balancer://martin-cluster/" timeout=10 failontimeout=on> | |
RequestHeader set X-Forwarded-Proto "https" | |
BalancerMember "http://192.168.1.2:8080" route=1 ttl=5 ping=500ms loadfactor=1 retry=3 | |
BalancerMember "http://external-domain.com" route=3 ttl=5 ping=500ms loadfactor=1 retry=3 status=+H | |
ProxySet lbmethod=byrequests | |
Order deny,allow | |
Allow from all | |
</Proxy> | |
<Proxy "balancer://martin-cluster-ws/" timeout=10 failontimeout=on> | |
BalancerMember "ws://192.168.1.2:8080" route=1 ttl=5 ping=500ms loadfactor=1 retry=3 | |
BalancerMember "ws://external-domain.com" route=3 ttl=5 ping=500ms loadfactor=1 retry=3 status=+H | |
ProxySet lbmethod=byrequests | |
Order deny,allow | |
Allow from all | |
</Proxy> | |
<Proxy *> | |
Order deny,allow | |
Allow from all | |
</Proxy> | |
RewriteCond %{REQUEST_URI} ^/socket.io [NC] | |
RewriteCond %{QUERY_STRING} transport=websocket [NC] | |
RewriteRule /(.*) balancer://martin-cluster-ws/$1 [P,L] | |
ProxyPass "/" "balancer://martin-cluster/" | |
ProxyPass "/socket.io/" "balancer://martin-cluster-ws/socket.io" | |
ProxyPassReverse "/socket.io/" "balancer://martin-cluster-ws/socket.io" | |
</VirtualHost> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment