This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have Dawn & David Griffiths on-line!
See this thread for details.
The moose likes Tomcat and the fly likes Tomcat returns 302 back to Apache via AJP13 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Tomcat returns 302 back to Apache via AJP13" Watch "Tomcat returns 302 back to Apache via AJP13" New topic

Tomcat returns 302 back to Apache via AJP13

Andre Enimot
Ranch Hand

Joined: Jul 29, 2009
Posts: 31
Hi Guys,

I am trying to setup a home website (say "") with Apache2-->mod_jk/ajp13-->Tomcat6. When I go to the site from outside network by typing my home IP, it works ok. But when I go to, it does not work. I examined a debug-level logging from mod_jk, and see that request comes in, mod_jk finds a wildcard match, connects to Tomcat6 socket, sends request via AJP13, but in response gets 302 "Moved Temporarily", and eventually apache2 returns index.html. In case when I type IP address instead of domain name, everything is the same except response from Tomcat is not 302 but correctly rendered page.

So it looks like Tomcat refuses to serve requests that comes with domain name. I have VirtualHost *:80 in apache2 named "", and also in Tomcat's Engine defaultHost="" and a Host with name="". I am running standalone Tomcat6 from inside Eclipse, but have the above settings in server.xml in Tomcats conf folder and also in Eclipse's Server deployment folder. What I am doing wrong, please help?

Thanks in advance!
K. Gil
Ranch Hand

Joined: Apr 29, 2011
Posts: 75

it doesn't matter what "virtualhost" is called in apache, try to check apache ServerName and ServerAlias for this virtualhost
and remember that ServerName is passed to tomcat through AJP, and tomcat needs revelant entry: hostname = apache servername
Andre Enimot
Ranch Hand

Joined: Jul 29, 2009
Posts: 31
Thank you for the hint, the config parameters were as you described, names were matching. But the culprit turned out to be very simple -- the ServerName I was using was too long (because I mistakenly thought it must be same as domain name) -- 31 chars total. After I shortened the server/host names things work fine.
It is sorta covered in the JavaRanch Style Guide.
subject: Tomcat returns 302 back to Apache via AJP13
It's not a secret anymore!