skip to Main Content

I have a tomcat(running on 8080) application on my cent os server and i can access it with the url:

SERVER_IP:8080/myapp

and I have my admin panel on

SERVER_IP:8080/myapp/admin

and I have an apache server running on port 80.

I have two domains :

www.myapp.com
admin.myapp.com

I’ve managed to configure tomcat, mod_jk and apache server such that admin.myapp.com url opens the tomcat home page(SERVER_IP:8080).

But what I want is to make admin.myapp.com url to open SERVER_IP:8080/myapp/admin and www.myapp.com to open SERVER_IP:8080/myapp.

I need to make apache know when a request came to admin.myapp.com, it should know to redirect the request to SERVER_IP:8080/myapp/admin. Something is missing obviously.

Here are my configurations :

httpd.conf (admin.myapp.com.conf actually because it is created by plesk panel but i think it’s irrevelant)

<VirtualHost SERVER_IP:80 >
    ServerName "admin.myapp.com:80"
    ServerAlias "www.admin.myapp.com"
    ServerAlias "ipv4.admin.myapp.co"
    ServerAdmin "[email protected]"
    UseCanonicalName Off

    JkMount / ajp13
    JkMount /* ajp13

    ....
</VirtualHost>

mod_jk.conf

# Load mod_jk module
# Update this path to match your modules location
LoadModule jk_module modules/mod_jk.so

# Where to find workers.properties
# Update this path to match your conf directory location
JkWorkersFile /usr/local/tomcat7/conf/workers.properties

# Where to put jk logs
# Update this path to match your logs directory location
JkLogFile /usr/local/tomcat7/logs/mod_jk.log

# Set the jk log level [debug/error/info]
JkLogLevel debug

# Select the log format
JkLogStampFormat "[%a %b %d %H:%M:%S %Y]"

# JkOptions indicate to send SSL KEY SIZE,
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories

# JkRequestLogFormat set the request format
JkRequestLogFormat "%w %V %T"

workers.properties

# Define 1 real worker named ajp13
worker.list=ajp13

# Set properties for worker named ajp13 to use ajp13 protocol,
# and run on port 8009
worker.ajp13.type=ajp13
worker.ajp13.host=localhost
worker.ajp13.port=8009
worker.ajp13.lbfactor=50
worker.ajp13.cachesize=10
worker.ajp13.cache_timeout=600
worker.ajp13.socket_keepalive=1
worker.ajp13.socket_timeout=300

Thanks in advance.

2

Answers


  1. Chosen as BEST ANSWER

    After all, I came up with this solution using mod_proxy instead mod_jk as slash mentioned in the other answer. But what did worked for me is as below :

    ProxyPass / http://SERVER_IP:8080/ 
    ProxyPass /myapp/ http://SERVER_IP:8080/myapp
    

    And then I added following line for cookies :

    ProxyPassReverseCookiePath /myapp /
    

  2. The easiest way to achieve this is by using mod_proxy
    Load mod_proxy module in your httpd.conf

    <VirtualHost SERVER_IP:80>
    
         ServerName admin.myapp.com
         ServerAlias www.myapp.com
         ServerAlias www.admin.myapp.com
         ServerAlias ipv4.admin.myapp.co
         ServerAdmin [email protected]
         # Any additional configuration/customization.
    
         RewriteEngine on
         RewriteCond %{HTTP_HOST} ^admin.myapp.com$ [NC]
         RewriteRule ^(.*)$ http://SERVER_IP:8080/myapp/admin/$1 [R=301,L]
    
         ProxyRequests Off    
         ProxyPass / ajp://SERVER_IP:8009/
         ProxyPass /myapp/ ajp://SERVER_IP:8009/myapp
    
    
    </VirtualHost>
    

    You can also achieve load balancing by enabling mod_proxy_balancer. It’s an extension of mod_proxy for load balancing.

    Check out pros and cons of mod_proxy and mod_jk here

    Good Luck!

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search