Using Reverse Proxy w/Rewrite AND Custom Header


We are trying to fight this problem for a day hunting Google for solutions, but unfortunately nothing seem to work. What we are simply trying to achieve:
1. Proxy traffic from `/.*` to reverse proxy ONLY if User-Agent matches
2. Proxed traffic has to go to a https backend
3. URL has to be rewritten, so when user visits the backend request will be https://backend/
4. Every request to a backend has to be authenticated with custom token header

We were able get either #3+1 (using Apache rewrite) OR #4 (using context) but not all with lsws. Configuring this with Apache is as easy as:
Apache config:
RequestHeader set X-Auth-Token "...."
RewriteCond %{HTTP_USER_AGENT} magic_ua [NC,OR]
RewriteRule (.*) http://backend/$1 [P,L]

How to achieve something like that in LiteSpeed Web Server?

After studying OpenLSWS code I found a workaround which seem to work, but I'm afraid I may be breaking something else.
1. Set rewrite rule:
Apache config:
RewriteRule /https?: - [F]
RewriteCond %{HTTP_USER_AGENT} magic_ua [NC,OR]
RewriteRule (.*) /$1 [L]
2. Setup External App with URL=http://backend:1234 and RequestHeader Set X-Auth-Token
3. Setup context w/type=Proxy with URL exp:/https?:.* pointing to External App from #2

It seems like LSWS will evaluate rewrite and then jump to search for context, which matches for proxing.

Last edited by a moderator:
@NiteWave that's the very first thing I've tried ;)


If you are saying this should work I see another culprint which may be my failure: we run OpenLSWS on local for testing and save Enterprise for production. I will rather not test in production ;)

Is the rewrite support here different between OpenLSW and Enterprise, so that
RequestHeader set X-Auth-Token
does not work?