Apache Rewrite or proxy

DrogoNevets picture DrogoNevets · Aug 13, 2012 · Viewed 20.3k times · Source

I have an Apache server running on my machine (port 80) I have a Zope server running on my machine (port 8080)

i want all users, irrespective of domain (lets use www.example.com for now) to be pushed to the zope instance, seamlessly

IE if i type into my browser http://www.example.com/mysite

it will display the effects of http://www.example.com:8080/mysite

BUT

i want the URL to still say http://www.example.com/mysite

(sub-)domain should be irrespective, as will have 2 or 3 domains pointing to the same server

am i supposed to be looking at mod_rewrite or mod_proxy?

I have the mod_rewrite half working,l but it changes what is in the browser?

currently trying

RewriteEngine on    
RewriteRule ^($|/.*) http://localhost:8080/$1 [P]

but getting server 500

Connecting using "http://localhost/mysite"

Answer

larsks picture larsks · Aug 13, 2012

You can use either mod_rewrite with a P (proxy) rule or mod_proxy to do what you want. Using mod_rewrite your configuration would look something like this:

RewriteRule ^/mysite/(.*) http://www.example.com:8080/mysite/$1 [P]

Using mod_proxy, your config would look like this:

<Location /mysite/>
  ProxyPass http://www.example.com:8080/
  ProxyPassReverse http://www.example.com:8080/
</Location>

Both accomplish approximately the same thing. Using a Location block with ProxyPass makes it easy to apply other configuration directives to this path on the front-end server.