Tutorial :Apache+Tomcat6+Struts2 redirect problem



Question:

I'm using apache on 80 port, that forwarding all requests on tomcat6 on port 8080. In my application I'm using struts2 framework. In tomcat I'm using redirect from ROOT application to my application "MyApp".

When I walk on the links on my site I see good URLs like www.mysite.com/order

But when struts redirects me anywhere URLs take the form like www.mysite.com:8080/MyApp/order

How to make this URLs simmilar?


Solution:1

I do it using the AJP connector between Apache and Tomcat. Here's a snippet of what I use in my config files:

Part of Apache's configuration ($APACHE_DIR/sites-available/default):

NameVirtualHost *:80  NameVirtualHost *:443    LoadModule    jk_module  /usr/lib/apache2/modules/mod_jk.so  JkWorkersFile /etc/apache2/workers.conf  JkLogFile     /var/log/apache2/mod_jk.log  JkLogLevel    info  JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "    <VirtualHost *:80>      ServerName brasee.com      ServerAlias www.brasee.com      JkMount /* ajp13secured  </VirtualHost>  

Part of Tomcat's configuration (conf/server.xml):

<Connector port="8080" protocol="HTTP/1.1"             connectionTimeout="20000"             redirectPort="8443" />  <!-- Define an AJP 1.3 Connector on port 8008 -->  <Connector port="8008" protocol="AJP/1.3" redirectPort="8080" />  


Solution:2

How are you doing the forwarding? The correct way will be to set up Apache as reverse proxy using mod_proxy. See here for instructions. This way there will be no problem with Struts redirects.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »