Host replace for proxy configuration

gdewey

Well-Known Member
#1
Hi, I need to replace the host from the backend server to the front on a proxy server configuration.

I am using a basic rule

RewriteRule (.*) http://192.168.120.47:80/$1 [p]

in the web ReWrite rule web gui of the LSWS

but I am getting a 500 Internal Error

what is the rule missing? My guess is that this rule is making a redirection to the same host causing a loop. But how do I replace the HTML ahref on demand so user see the proxy host and not the backend host.


your help is appreciate it
 
Last edited:

gdewey

Well-Known Member
#3
Tks for the pointer NiteWave but my proxy and cache works perfect (based on that same article), the problem is the links. They are preserved as the backed are. I need them to change to my proxy domain (in y case ip) so the user can navegate via the proxy. I would asume a ReWrite Rule is needed unless the proxy type in the Context makes that in automatic and I am missing a setting.
 

gdewey

Well-Known Member
#5
ohh I see, I had the idea that test-proxy was the actual dns host but its the internal given name of the webserver external app.

ok I have now

RewriteRule (.*) http://VanguardiaWeb/$1

and its not giving a log error any more. and its doing the proxy on the first request, but links are still being as the back end webserver

are there aditional instructions to give to replace this links?

tks
 

gdewey

Well-Known Member
#7
can't miss the [P] flag for proxy.

==>
RewriteRule (.*) http://VanguardiaWeb/$1 [P]
sorry I didnt copy and paste correct. I do have

RewriteRule (.*) http://VanguardiaWeb/$1 [P]

just confirming.. "VanguardiaWeb" is the given name of the External app under the Server, type WebServer right?

the thing is that VanguardiaWeb external webserver has a certain IP lets call it X, the idea is to have the links turned into the VHost IP and not the X Webserver

tks
 

webizen

Well-Known Member
#8
...
the thing is that VanguardiaWeb external webserver has a certain IP lets call it X, the idea is to have the links turned into the VHost IP and not the X Webserver
...
Are you saying you want to be 301 redirected to the actual website instead of being proxy'd? Then no "[p]" (proxy flag) is needed.

RewriteRule (.*) http://www.example.com/$1 [L,R=301]
www.example.com is the FQDN of the site.
 

gdewey

Well-Known Member
#9
Hi Webizen, I want to proxy not to be 301 redirected

the idea is pretty basic.

I need

Front End VH with cache
Back End External App

Everthing works well when I first use as client the Front End VH. But the links on the webpage do not get rewrite, they have the Back End URL. They should have the Front Ends so they can keep on the proxy while navigating.

I use to have this in IIS where a third party api would rewirte and change all links on the webpage to the given host so we could "hide" or protect the application server.
 

gdewey

Well-Known Member
#11
Its a trial I downloaded 2 days ago. Version 4.2.2 Ent for 2 CPU Expiration Apr 02, 2013 :)

gdewey@ubuntu:/etc/network$ ls -lt /usr/local/lsws/bin/lshttpd*;date;date -u
lrwxrwxrwx 1 root root 15 Mar 18 22:33 /usr/local/lsws/bin/lshttpd -> ./lshttpd.4.2.2
-r-xr-xr-x 1 root root 11956833 Mar 18 22:33 /usr/local/lsws/bin/lshttpd.4.2.2
Wed Mar 20 19:30:17 CST 2013
Thu Mar 21 01:30:17 UTC 2013

one question.. the rewrite/proxy does change the links to the front end VH right? (regardless I might be having a bad config or something)..
 
#12
the rewrite/proxy has been working for long, and I've done many tests on this function in the past. I'd share more experience after you've got it working, for example, how to get it working with cache in rewriterule.

please check if you've defined proxy context at the same time.
if so, best to delete them to reduce conflict. forgot to ask, if the virtual host defined in lsws admin console(i.e., native vhost) or come from apache's httpd.conf ?
 

gdewey

Well-Known Member
#13
the rewrite/proxy has been working for long, and I've done many tests on this function in the past. I'd share more experience after you've got it working, for example, how to get it working with cache in rewriterule.

please check if you've defined proxy context at the same time.
if so, best to delete them to reduce conflict. forgot to ask, if the virtual host defined in lsws admin console(i.e., native vhost) or come from apache's httpd.conf ?
Hi Nite, if I defined the context at the same time as what? or where else?

Virtual Host was created in the admin console. Does not come from apache.
 
#14
for example in your case, if you define a proxy context which URI is /, then your all your rewriterules should be useless, whether they are parsed or not.

enable debug log and rewrite log, you can see the details how there rules are processed and what's the final result.

debug log:
admin console->Actions->Toggle Debug Logging

rewrite log:
select a vhost->Rewrite->Enable Rewrite:Yes; Log Level:9
 

gdewey

Well-Known Member
#15
yes that is my case. proxy context is / .. so how do I set rewrite rules for this type of context so they apply to it?

let me enable the logs to tail them while testing
 

gdewey

Well-Known Member
#17
ok understood. I took the rule out and tested also disabled the rewrite engine but no luck. still the backend site gives links as original.

there is one thing that I belive it might be affecting

the proxy is calling the back end server with an ip..

but the backend server has a rewriter that sets a hostname ..

would it be possible that the match of the rewrite is not being done because the lsws belives the match is the ip and not the rewriten host on the backend?
 

gdewey

Well-Known Member
#19
this one fits perfect
RewriteRule ^(.*)$ http://node1/$1 [P,E=Proxy-Host:www.example.com]

from what I understand I can set a custom host regardless the target server host.

The problem is that I am on the / context and cannot use ReWrite rules as you mention.. I tried that rule before but didn't took any effect :(

any ideas to keep the / context and still be able to set rewrite rules?
 
#20
I encountered exact same issue as you before ... you can keep other context like /abc/ at the same time but can't keep context / since it matchs everything.

and in rewriterule you can do almost everything which a contect can, and, in context, no such "Proxy-Host" function yet, so any special requirement which must use context ?
 
Top