views:

190

answers:

2

On my laptop, with Apache

I have different web apps in various directories on my laptop, that I can start using simple webservers listening on different ports. For example

~/app1/./app.pl
>> listening on http://localhost:3000/

~/app2/./app.pl
>> listening on http://localhost:3001/

~/app3/./app.pl
>> listening on http://localhost:3001/

I want to access the above from my browser like so

http://localhost/app1
http://localhost/app2
http://localhost/app3

Can I do the above with mod_proxy? If so, how?

Update: I must add that I have Googled for mod_proxy, read the tutes on Apache's website, and experimented with the following

uncommented the following in my httpd.conf

LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_connect_module modules/mod_proxy_connect.so
LoadModule proxy_http_module modules/mod_proxy_http.so

added the following in my httpd.conf

<IfModule mod_proxy.c>
    ProxyRequests On
    ProxyPass /app1 http://localhost:3000/
    ProxyPassReverse /app1 http://localhost:3000/
    ProxyPass /app2 http://localhost:3001/
    ProxyPassReverse /app2 http://localhost:3001/
    ProxyPass /app3 http://localhost:3002/
    ProxyPassReverse /app3 http://localhost:3002/
</IfModule>

Yet, I get HTTP 404 when I try to access the above apps.

A: 

Yes you can. Googling "mod_proxy tutorial" has plenty of results...

In particular you'll want to use mod_proxy_ajp if your server supports the AJP protocol. (Such as Tomcat.)

Jeremy
Thanks, but no, I don't even want to go near Tomcat.
punkish
@punkish: It was just an example and AJP is also used in Jetty. I did not say it was only Tomcat.
Jeremy
+1  A: 

I would do this using mod_rewrite and mod_proxy. For example (the following rules go into your VirtualHost configuration):

RewriteEngine On
RewriteRule ^/app1(.*)$ http://localhost:3000/$1 [P]
RewriteRule ^/app2(.*)$ http://localhost:3001/$1 [P]
RewriteRule ^/app3(.*)$ http://localhost:3002/$1 [P]

These rules use mod_rewrite's [P] flag to proxy the request. You'll need to make sure that mod_proxy, mod_proxy_http and mod_rewrite are all loaded in your main apache configuration by adding/uncommenting:

LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule rewrite_module modules/mod_rewrite.so
ollyc
ok, let me get this straight... do I need to use mod_proxy *with* mod_rewrite?
punkish
yes, you'd need both mod_proxy and mod_rewrite enabled for this to work. You can do it with mod_proxy alone (and in a simple case like yours that might be better) but mod_rewrite gives you more flexibility when mapping URLs, so it's normally my first choice for this job.
ollyc
ok. Could you please spell this step by step? If you see from my note above, I am unable to make this work with mod_proxy. What am I doing wrong? What should I be doing? I don't have to worry about mapping URLs because my web application does that by itself. I just want to point the browser to http://localhost/app1, but have Apache redirect it behind the scene to http://localhost:3000/
punkish