Host replace for proxy configuration

Discussion in 'Install/Configuration' started by gdewey, Mar 20, 2013.

  1. gdewey

    gdewey Well-Known Member

    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 (.*)$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: Mar 20, 2013
  2. NiteWave

    NiteWave Administrator

  3. gdewey

    gdewey Well-Known Member

    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.
  4. NiteWave

    NiteWave Administrator

    in your case:

    Name: test-proxy

    your rewrite rule change to:

    RewriteRule (.*) http://test-proxy/$1 [p]
  5. gdewey

    gdewey Well-Known Member

    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?

  6. NiteWave

    NiteWave Administrator

    can't miss the [P] flag for proxy.

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

    gdewey Well-Known Member

    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

  8. webizen

    webizen Well-Known Member

    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. is the FQDN of the site.
  9. gdewey

    gdewey Well-Known Member

    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.
  10. NiteWave

    NiteWave Administrator

    what's the lsws version used?

    please give the output of
    #ls -lt /usr/local/lsws/bin/lshttpd*;date;date -u
  11. gdewey

    gdewey Well-Known Member

    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. NiteWave

    NiteWave Administrator

    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 ?
  13. gdewey

    gdewey Well-Known Member

    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. NiteWave

    NiteWave Administrator

    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
  15. gdewey

    gdewey Well-Known Member

    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
  16. NiteWave

    NiteWave Administrator

    this rewriterule do same as proxy / context:
    RewriteRule (.*) http://VanguardiaWeb/$1 [P]

    but don't use them at the same time. use either one.
  17. gdewey

    gdewey Well-Known Member

    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?
  18. NiteWave

    NiteWave Administrator

    Last edited: Mar 21, 2013
  19. gdewey

    gdewey Well-Known Member

    this one fits perfect
    RewriteRule ^(.*)$ http://node1/$1 [P,]

    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. NiteWave

    NiteWave Administrator

    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 ?

Share This Page