*
The moose likes Tomcat and the fly likes Redirection rules for Apache Web Server\Tomcat 7 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Redirection rules for Apache Web Server\Tomcat 7" Watch "Redirection rules for Apache Web Server\Tomcat 7" New topic
Author

Redirection rules for Apache Web Server\Tomcat 7

M Burke
Ranch Hand

Joined: Jun 25, 2004
Posts: 388
I want to set up a redirect that does this...

On the Tomcat server, running on port 8080 I have an application with this url http://localhost:8080/MyApp
Port 8080 is blocked from the outside
Apache Web Server is on port 80 and services public requests for Tomcat.

And on the public Internet, a user types in..
http://www.publicwhatevermywebsite.com

It then redirects to the application. But in the browser url it says
http://www.publicwhatevermywebsite.com/MyApp

I want it to say
http://publicwhatevermywebsite.com without the /MyApp part.

I researched the httpd-vhost.xml file in the web server, but to no avail.



Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41062
    
  43
You need to adapt Tomcat's server.xml file. You probably need something like this:


Ping & DNS - my free Android networking tools app
M Burke
Ranch Hand

Joined: Jun 25, 2004
Posts: 388
Ulf Dittmer wrote:You need to adapt Tomcat's server.xml file. You probably need something like this:



I am getting 'Page not found'. There is already a <host> tag for localhost. Do I need to combine them some how?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41062
    
  43
Yes, and adapt the "appBase" attribute to your circumstances.
K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2231
    
    7

Not sure if you need this, the Tomcat mod_jk module should be installed too. Then the Tomcat server need to add some config (exactly what I can't recall).

Then in apache server make a conf file having the line:



Then in the apache httpd.conf add the line at the bottom:



Then restart tomcat and apache.

I have done this redirection thing for Glassfish app server so Tomcat should be similar.


K. Tsang JavaRanch SCJP5 SCJD/OCM-JD OCPJP7 OCPWCD5
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15951
    
  19

There are 2 ways to solve this common problem when you have Apache HTTPD + Apache Tomcat. Both involve using Apache HTTPD as a proxy server for Tomcat.

The Apache mod_jk module is the traditional way to do this. It establishes a tunnel from Apache HTTPD to Tomcat via Tomcat's proxy port (8009). You provide proxy configuration in the Apache configuration file(s) that includes the external URL pattern and the Tomcat URL translation of that pattern. The Tomcat server also has worker directives to assist in the process.

The Apache mod_proxy module is the newer and preferred way to do this. It works much like mod_jk, except that it's simpler to configure and you don't have to make any configuration changes on the Tomcat side. However, mod_proxy should be used with care. If you set up a reverse proxy as an open proxy (which isn't hard to do), a whole army of nasty people based on Taiwan's HINET ISP service will show up like flies around a dead animal and within 2-3 days, your system will be so busy operating as a spam relay that it won't be usable for anything else.

I'm picking on HINET specifically since they're atrociously notable offenders to the point where my network has banned thousands of HINET IP addresses, but actually would-be spammers anywhere in the world can - and will - do the same.

Customer surveys are for companies who didn't pay proper attention to begin with.
 
jQuery in Action, 2nd edition
 
subject: Redirection rules for Apache Web Server\Tomcat 7
 
Similar Threads
running Apache and Tomcat together
Tomcat Load balancing using mod_rewrite
Redirect behind proxy
how to redirect from apache to tomcat..?
Cookies in Apache