0

I have an application running on tomcat at http://www.example.com:9090/mycontext. The host name in server.xml points to www.example.com. I do not have localhost anymore. I am using apache to forward requests to tomcat using mod_proxy. Things work fine as long as the ProxyPath is /mycontext. The server name setup in virtual host is www.abc.com and http://www.abc.com/mycontext works fine. However I would like to ignore the context path and simply use http://www.abc.com/ to forward requests to http://www.example.com:9090/mycontext. When I do this, apache shows me a blank page. What am I missing here? I have not changed anything in server.xml except the default host to www.example.com.

<VirtualHost *:80>
 ServerName www.abc.com

 ProxyRequests Off
 ProxyPreserveHost On

 <Proxy *>
 Order deny,allow
 Allow from all
 </Proxy>

 ProxyPass / http://www.example.com:9090/mycontext
 ProxyPassReverse / http://www.example.com:9090/mycontext
 </VirtualHost>

Thanks

sschrass
  • 103
  • 4
user10211
  • 19
  • 1
  • 5

1 Answers1

2

Matching trailing slashes are important in mod_proxy.

ProxyPass / http://www.example.com:9090/mycontext

This will take a request to http://www.abc.com/something and proxy it to http://www.example.com:9090/mycontextsomething - not terribly helpful!

Try this configuration, instead:

ProxyPass / http://www.example.com:9090/mycontext/
ProxyPassReverse / http://www.example.com:9090/mycontext/

Also - if Tomcat's expecting www.example.com as a host header, then you probably do not want that ProxyPreserveHost On directive.

Shane Madden
  • 114,520
  • 13
  • 181
  • 251
  • Thanks a lot for your help. The solution partially worked. With the trailing slash added, a page should be shown when http ://www.abc.com/ is requested which corresponds to http ://www.example.com:9090/mycontext/. Instead it goes to the "It works" page. For other URLs such as http ://www.abc.com/test it does take me to http ://www.example.com:9090/mycontext/test. How do I solve the first bit? – user10211 Apr 14 '12 at 10:13
  • Is it Apache's "It works" page, or Tomcat's? – Shane Madden Apr 14 '12 at 18:40
  • It is Apache's "It works page." – user10211 Apr 15 '12 at 04:44
  • Interesting... are you sure the request to `/` has the correct host header to get mapped to this virtual host? – Shane Madden Apr 16 '12 at 01:49
  • I checked the apache access log. It shows that a request made to / gets directed to /mycontext/. Should it explicitly show http://www.example.com:9090/mycontext/ – user10211 Apr 16 '12 at 12:36
  • Ahh, I see. Do you need for it to make that request without the trailing slash? That'll be more complicated to add to the config. – Shane Madden Apr 16 '12 at 15:20
  • Essentially my tomcat setup is serving a JSP page at :9090/mycontext/ and I would like http: //www.abc.com/ to get redirected to this page. Does it involve rewrite rules setting up for just this redirection ? – user10211 Apr 17 '12 at 04:10
  • No, that should be working just fine. Can you clarify what you meant by "It shows that a request made to / gets directed to /mycontext/" - is that not what you're looking to achieve? – Shane Madden Apr 17 '12 at 04:14