logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Apache View previous topic :: View next topic
Reply to topic   Topic: just rewrite (to proxy) if external ressource exists
Author
DrSarez



Joined: 23 Oct 2012
Posts: 3

PostPosted: Mon 29 Oct '12 16:20    Post subject: just rewrite (to proxy) if external ressource exists Reply with quote

Hello everybody,

I use Apache as a reverse proxy. There is no web content on the dedicated server itself. If a client requests a resource on the local Apache server, Apache should determine on which remote (proxied) server the resource exists and do a proxy rewrite to that server. A snippet should (that currently does not work) should demonstrate, what i would do:

Code:

RewriteCond               http://200.202.204.11:3000%{REQUEST_URI}    -U
RewriteRule     ^(.*)$    http://200.202.204.11:3000$1                [P]


I spared out the rest of my configuration (ProxyPass, ProxyPassReverse, other RewriteCond,...) to focus on my problem:

How could I check if an external resource exists / is available before rewriting? The -U option for RewriteCond returns alwas true. The -F option returns alwas false. Is there a working solution for my intent?
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7371
Location: Germany, Next to Hamburg

PostPosted: Tue 30 Oct '12 18:21    Post subject: Reply with quote

A pure reverse proxy would just be
Code:

ProxyPass / http://200.202.204.11:3000/
ProxyPassReverse / http://200.202.204.11:3000/


I wonder why you also need to rewrite the urls.

With a pure reverse proxy you will get a 503 error if the backend server is not available. That page you could customise.

Else you might want several backend machines and run apache as a loadbalancer.
Back to top
DrSarez



Joined: 23 Oct 2012
Posts: 3

PostPosted: Tue 30 Oct '12 21:36    Post subject: Reply with quote

Thank you for your help James.

The reason I use rewriting is the backend server breaks out the subdirectory.

For a backend server like '<ip>/subdir1' the directive 'ProxyPass /subdir1 <ip>/subdir1' works pretty well. But for a backend server like '<ip>' the directive 'ProxyPass /subdir2 <ip>' does not work.

The problem becomes more clear if you take a look at the TCP traffic:

Gitlab in a subdir
https://docs.google.com/open?id=0B224NXXd_k9URVdmVVR2YUFHV2c

Proxmox in a subdir
https://docs.google.com/open?id=0B224NXXd_k9UNmRNTmNpcnk4TEU

Here is the full config that should handle this problem. It would, if the -U option would work:

Code:
ProxyRequests Off
SSLProxyEngine On
<Proxy *>
      Order deny,allow
      Allow from all
</Proxy>

# Reverse-Proxys

<Location /ajaxplorer>
      ProxyPass               http://200.201.202.8/ajaxplorer
      ProxyPassReverse        http://200.201.202.8/ajaxplorer
</Location>

<Location /gitlab>
      ProxyPass               http://200.201.202.11:3000
      ProxyPassReverse        http://200.201.202.11:3000
      ProxyPassReverse        http://thomassteinbach.homeip.net
</Location>

<Location /proxmox>
      ProxyPass               https://200.201.202.2:8006
      ProxyPassReverse        https://200.201.202.2.8006
</Location>

# try to find rest of reverse resources
RewriteEngine  on

## GITLAB
# check if url already points to a proxied service
RewriteCond      %{IS_SUBREQ}      =false
RewriteCond      %{REQUEST_URI}      !^/ajaxplorer
#RewriteCond   %{REQUEST_URI}      !^/gitlab
RewriteCond      %{REQUEST_URI}      !^/proxmox
## if resource doesn't exist locally, proxy to gitlab
RewriteCond      http://200.201.202.11:3000%{REQUEST_URI}         -U
RewriteRule      ^(.*)$             http://200.201.202.11:3000$1   [P]

## PROXMOX
# check if url already points to a proxied service
RewriteCond      %{IS_SUBREQ}      =false
RewriteCond      %{REQUEST_URI}      !^/ajaxplorer
#RewriteCond   %{REQUEST_URI}      !^/gitlab
RewriteCond      %{REQUEST_URI}      !^/proxmox
## if resource doesn't exist locally, proxy to proxmox
RewriteCond      https://200.201.202.2:8006%{REQUEST_URI}         -U
#RewriteRule   ^(.*)$            https://200.201.202.2:8006$1   [P]
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7371
Location: Germany, Next to Hamburg

PostPosted: Tue 30 Oct '12 22:39    Post subject: Reply with quote

DrSarez wrote:

The reason I use rewriting is the backend server breaks out the subdirectory.


Did you try mod_proxy_html?
Back to top
DrSarez



Joined: 23 Oct 2012
Posts: 3

PostPosted: Thu 08 Nov '12 15:18    Post subject: Reply with quote

Yes I tried, but that did not work for URIs coming from scripts.

After searching for weeks to get the solution I come to the conclusion: there is no reliable RewriteRule if an external ressource exists.

You go much better if you address your service behind an reverse proxy via subdomains. E.g. 'gitlab.youdomain.net' if you want to address a ressource on your gitlab server behind your reverse proxy. So the reverse proxy does not become confused if the ressource is lying in the root directory '/' of the gitlab server.
Back to top


Reply to topic   Topic: just rewrite (to proxy) if external ressource exists View previous topic :: View next topic
Post new topic   Forum Index -> Apache