Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I want to run a Tomcat application through a regular website URL, such as www.xyz.com. I would like the root of this domain to act as the base directory for the web application, so each request to www.xyz.com/a/b/c becomes www.abc.com:8080/myApp/a/b/c. Ideally, I would be able to do this transparently and only for certain webapps.

www.abc.com:8080 should still respond to requests.

What do I need to do to make this happen?

share|improve this question
add comment

3 Answers

ProxyPass        / http://www.abc.com:8080/myApp/
ProxyPassReverse / http://www.abc.com:8080/myApp/

Read more about mod_proxy

share|improve this answer
    
this is the best solution to do this –  Mike May 15 '10 at 12:33
1  
To address the "only for certain webapps" side, just make the redirect path deeper. So: ProxyPass /a/b/c abc.com:8080/myApp/a/b/c ProxyPassReverse /a/b/c abc.com:8080/myApp/a/b/c To proxy all except certain paths, leave the ProxyPassReverse line but replace the ProxyPass lines with RewriteRules (making sure to use the [P] option to proxy rather than redirect), and make earlier rules to not proxy those paths. RewriteRule /notproxied - [L] RewriteRule /(.*) abc.com:8080/myApps/$1 [P] ProxyPassReverse / abc.com:8080/myApp –  Jeremy M Jul 14 '10 at 17:39
add comment

You can use mod_rewrite in Apache to do this. Load mod_rewrite in your Apache and in your www.xyz.com vhost add the following rule:

RewriteRule ^/(.*) http://www.abc.com:8080/myApp/$1

This should do the magic.

More info about mod_rewrite here.

EDIT: In order to keep the site name in the browsers, use mod_proxy as well by just appending a [P] at the end of the RewriteRule:

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

This will force Apache to act as a proxy for that URL instead of just rewriting the URL.

share|improve this answer
    
This causes the browser to actually redirect. This works, but I would prefer if the site appeared as www.xyz.com from the user's side. –  Stefan Kendall May 14 '10 at 15:28
1  
use mod_proxy as well, and in the end of the RewriteRule append a [P], like this: RewriteRule ^/(.*) abc.com:8080/myApp/$1 [P]. I've also edited the answer above to include this info. –  Marco Ramos May 14 '10 at 15:56
add comment

A simpler method for doing this is to just add a Virtual Host entry in your Apache conf file. Usually located in /etc/httpd/conf, add something like this at the end of the Virtual Host section:

<VirtualHost X.X.X.X:80>
ServerName tomcatpage.yourdomain.com
ServerAlias tomcatpage.yourdomain.com
Redirect permanent / http://tomcatpage.yourdomain.com:8080/
</VirtualHost>

Restart your Apache service and you are done.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.