Reputation: 952
I'm working on setting up a websocket connection through a reverse_proxy. I finally have a working config for Nginx, but I would prefer to use Apache2.
These are the needed config lines in Nginx:
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
I tried to translate them to Apache2, but it doesn't seem to work:
<If "%{HTTP:upgrade} == 'websocket'">
RequestHeader add Upgrade "websocket"
</If>
RequestHeader set Connection "upgrade"
Apache2 just ignores these commands..When I change the header names they're not ignored anymore, but that doesn't help me:
RequestHeader set X-Connection "upgrade"
So: Apache2 seems to ignore changes to "Upgrade" and "Connection" headers.
(I'm working with a debugging server that prints all HTTP requests received with all their headers - so I can directly compare Nginx and Apache2 requests - and therefore I know that Apache2 is ignoring my command.)
How can I make this work in Apache2?
Upvotes: 3
Views: 5014
Reputation: 952
Found a solution myself: Apache doesn't allow to set these headers - instead you need to use the rewrite engine:
RewriteEngine On
RewriteCond %{HTTP:Connection} Upgrade [NC]
RewriteCond %{HTTP:Upgrade} websocket [NC]
RewriteRule /(.*) ws://127.0.0.1:3000/$1 [P,L]
Apache will then automatically add the correct "Upgrade" and "Connection" headers.
Upvotes: 10