.htaccess proxy pass through

Discussion in 'General' started by EvoIX_MR2006, May 27, 2010.

  1. EvoIX_MR2006

    EvoIX_MR2006 Active Member


    I am trying to use .htaccess to proxy a site through as a domain hosted on the litespeed server.

    This doesn't work:
    RewriteEngine on
    RewriteRule (.*) http://www.google.ca/$1 [P]

    But this does:
    RewriteEngine on
    RewriteRule (.*) http://www.google.ca/$1 [L]

    The latter redirects directly to google.ca. If I put an external App of type web server and set it to the google IP, and leave the .htaccess as the top example, it does a redirect instead of a reverse proxy.

    I beleive I asked about this a few months back, and was told the feature was being implemented? Can anyone confirm?

  2. mistwang

    mistwang LiteSpeed Staff

    You need to create a web server external app with name "www.google.ca".
  3. NiteWave

    NiteWave Administrator

    your example of google looks not good: it looks like google can detect this and refuse to be reverse proxy'ed.
    RewriteEngine on
    RewriteRule (.*) http://www.google.ca/$1 [P]
    assume the name of your external App of web server is google_backend, the rewrite rule should be
    RewriteEngine on
    RewriteRule (.*) http://google_backend/$1 [P,QSA]
    this can archive success partly:
    for example, access http://yousite.com/abcd, it will access google.ca/abcd, and return a "404 Not Found" page from google.

    However if you use your own site instead of google, should be successful.
  4. kolorafa

    kolorafa Member

    This topic is old but I noticed small but noticeable difference in LSWS [P] directive implementation (which in my opinion is buggy).

    Litespeed WebServer treats [P] as ordinary request to web server defined in External App tab. X-Forwarded-* are begin added but "host" stays same as requested. I came into problem trying to proxy to another virtual host on the same instance of litespeed - it just generated infinite loop.

    RewriteCond %{REQUEST_URI} \.(jpg|png|jpeg)$
    RewriteRule (.*) http://example.com/$1 [QSA,P]
    This rule will generate request (shown below) to web server name "example.com" when mod_proxy in the same situation calls hostname "example.com". As you can see it contains "Host: proxy_me_to_example.com" instead of "Host: example.com".
    GET /logo.png HTTP/1.1
    Host: proxy_me_to_example.com
    Connection: keep-alive
    Cache-Control: max-age=0
    Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
    User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36
    Accept-Encoding: gzip
    Accept-Language: en-US,en;q=0.8,pl;q=0.6
    X-Forwarded-Host: proxy_me_to_example.com
    Is there any workaround for this?
  5. mistwang

    mistwang LiteSpeed Staff

  6. kolorafa

    kolorafa Member

    Thank you for your reply. Unfortunately replacing [QSA,P] with suggested [P,E=Proxy-Host:example.com] didn't changed anything.
    I even moved rules to Rewrite tab (instead of using .htaccess) - nothings changed.

    p.s. I use normal lsws, not the o-s edition.
  7. mistwang

    mistwang LiteSpeed Staff

    It is a feature for enterrpise edition though.

Share This Page