Subject: Sundomain mapping with Apache httpd and Tomcat
Author: AwsEC2
In response to: Side notes for mod_jk installation 64-bit
Posted on: 05/12/2016 01:34:26 AM
Here comes the requirement
Two or more subdomains:
------- ----------
news.exmaple.com ---| | | |
| | mod_jk | tomcat |
www.exmaple.com ---| httpd |------------| |
| | | |
blog.exmaple.com ---|_______| |----------|
|
|
|-[+] webapps
|---[+] news
|---[+] blog
|---[+] main
Desired Mapping:
main domain:
www.exmaple.com/main --> /webapps/main
www.exmaple.com/blog --> /webapps/blog
www.exmaple.com/news --> /webapps/news
subdomain news:
news.exmaple.com --> /webapps/news
subdomain blog:
blog.exmaple.com --> /webapps/blog
Here comes the solutionhttpd.conf
<VirtualHost *:80>
ServerName exmaple.com
ServerAlias www.exmaple.com
<Directory /home/ec2-user/exmaple.com/html>
Options Indexes Includes FollowSymLinks
AllowOverride All
</Directory>
JkMount /main worker1
JkMount /news worker1
JkMount /blog worker1
JkUnMount /*.html worker1
</VirtualHost>
<VirtualHost *:80>
ServerName news.example.com
<Directory /home/ec2-user/news.exmaple.com/html>
Options Indexes Includes FollowSymLinks
AllowOverride All
</Directory>
JkMount / worker1
JkMount /* worker1
JkUnMount /*.html worker1
</VirtualHost>
<VirtualHost *:80>
ServerName blog.example.com
<Directory /home/ec2-user/blog.exmaple.com/html>
Options Indexes Includes FollowSymLinks
AllowOverride All
</Directory>
JkMount / worker1
JkMount /* worker1
JkUnMount /*.html worker1
</VirtualHost>
Tomcat server.xml
<Host name="news.example.com" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<Context docBase="/env/.../webapps/news" path="/" reloadable="true"/>
</Host>
<Host name="blog.example.com" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<Context docBase="/env/.../webapps/blog" path="/" reloadable="true"/>
</Host>
>
> On 08/30/2012 02:43:24 PM
AwsEC2 wrote:
1) Always get the latest version
$ cd /home/ec2-user
$ mkdir mod_jk
$ cd mod_jk
$ curl http://apache.osuosl.org/tomcat/tomcat-connectors/jk/
tomcat-connectors-1.2.37-src.tar.gz > tomcat-connectors-1.2.37-src.tar.gz
$ tar xzf tomcat-connectors-1.2.37-src.tar.gz
$ cd tomcat-connectors-1.2.37-src/native
$ ./configure --with-apxs=/usr/sbin/apxs
$ make
$ sudo make install
2) $ make may return 'make not found'
You may have to install first by
# yum install make
3) The install may change the location depending on your OS
For 32-bit: /usr/lib/httpd/modules/mod_jk.so
For 64-bit: /usr/lib64/httpd/modules/mod_jk.so
4) Accordingly, a working httpd.conf
# vi /etc/httpd/conf/httpd.conf
# Load mod_jk module
LoadModule jk_module /usr/lib64/httpd/modules/mod_jk.so
# Where to find workers.properties
JkWorkersFile /etc/httpd/conf/workers.properties
# Where to put jk shared memory
JkShmFile /var/log/httpd/mod_jk.shm
# Where to put jk logs
JkLogFile /var/log/httpd/mod_jk.log
# Set the jk log level [debug/error/info]
JkLogLevel info
# Select the timestamp log format
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
<VirtualHost *:80>
ServerName example1.com
ServerAlias www.example1.com
DocumentRoot /home/ec2-user/example1.com/html
SuexecUserGroup ec2-user ec2-user
<Directory /home/ec2-user/example1.com/html>
Options Indexes Includes FollowSymLinks
AllowOverride All
</Directory>
# Send servlet for context /examples to worker named worker1
JkMount /examples/servlets/* worker1
# Send JSPs for context /examples to worker named worker1
JkMount /examples/*.jsp worker1
</VirtualHost>
# /etc/init.d/httpd start
Starting httpd: [ OK ]
References: