Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Map virtual directory to another web server in apache

Tags:

http

apache

Is it possible to configure Apache web server to map a directory to a path on another web server? For example, can I make requests for http://server1/resource/ return http://server2/resource/. If this is possible, how do I go about setting this up?

like image 959
Nathan Avatar asked Jun 12 '09 03:06

Nathan


2 Answers

mod_proxy is the way to go

Use:

<Location /resource/>
    ProxyPass http://server2/resource/
    SetEnv force-proxy-request-1.0 1
    SetEnv proxy-nokeepalive 1
</Location> 
like image 72
stevedbrown Avatar answered Sep 22 '22 20:09

stevedbrown


mod_rewrite is pretty powerful for this. You'd setup a rewrite rule for /resource/ and use a 302 redirect to send people over to server two.

http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html

http://www.modrewrite.com/

Untested example:

<location "/">
 RewriteEngine On
 RewriteRule ^/resource/(.*)$ http://server2/resource/$1 [R]
</location>
like image 20
Gavin M. Roy Avatar answered Sep 19 '22 20:09

Gavin M. Roy