Using Reverse Proxy w/Rewrite AND Custom Header

#1
Hello!

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 https://example.com/foo/bar the backend request will be https://backend/https://example.com/foo/bar
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/http://example.com/$1 [P,L]

How to achieve something like that in LiteSpeed Web Server?


**Edit:**
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 (.*) /http://example.com/$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.

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

1541168278653.png


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
Code:
RequestHeader set X-Auth-Token
does not work?
 
Top