Recently help people with Apache+tomcat on the same IP server set up multi-domain to point to different sites, it took a lot of time. Especially when the configuration information, from the Internet to find a lot of information is wrong, mistakenly recognized not shallow. So write it down today for later use.
First of all, I need to say that: Apache as a front-end distributor, the content of the domain name resolution forwarded to the background tomcat up, Tomcat is only one, but has 2 different instances. is the 2 different websites respectively. Do not change to different domain names to the tomcat background of different websites up.
Now let's talk about the configuration process:
1. Enter Apache in the htpd.conf configuration:
#如果有2个以上域名必须写这句, make no mistake.
Namevirtualhost *:80
<virtualhost *:80>
ServerAdmin [email protected]
#网站放置的路径
DocumentRoot/*****/root
#申请的域名
ServerName *****.com
#通过mode_jk把所有该域名的http请求转发到worker3申明的tomca下
Jkmount/* Worker3
#错误信息打印的日志
Errorlog/usr/local/apache2/logs/error_log
#CustomLog/usr/local/apache2/logs/access_log
</VirtualHost>
#设置改路径下的权限为: Accessible, readable, writable
<Directory/home/tomcat/tomcat/webapps/ROOT>
Options Indexes FollowSymLinks
AllowOverride None
Order Allow,deny
Allow from all
</Directory>
#和上面一样的配置
<virtualhost *:80>
ServerAdmin [email protected]
#另一个网站路径
DocumentRoot/*****/company
#另一个域名
ServerName *****.com
#所有该域名下的请求发到ankaisteel申明的tomcat下
Jkmount/* Ankaisteel
Errorlog/usr/local/apache2/logs/error_log
#CustomLog/usr/local/apache2/logs/access_log
</VirtualHost>
<Directory/home/tomcat/tomcat/webapps/company>
Options Indexes FollowSymLinks
AllowOverride None
Order Allow,deny
Allow from all
</Directory>
#引用mod_jk的配置文件
Include conf/mod_jk.conf
2. Let's configure Workers.properties
#apache需要分发到后台tomcat域名的列表
Worker.list=worker3,ankaistee
# Set Properties Worker3 for Tomcat (AJP13)
Worker.worker3.type=ajp13
#这个名称一定要和tomcat的虚拟主机名配置成一样
Worker.worker3.host=localhost
worker.worker3.port=8010
Worker.worker3.lbfactor=50
worker.worker3.connection_pool_size=512
worker.worker3.connection_pool_timeout=600
Worker.worker3.socket_keepalive=1
Worker.worker3.socket_timeout=60
#worker. worker3.cachesize=10
#worker. worker3.cache_timeout=600
#worker. worker3.recycle_timeout=300
# Set Ankaisteel for Tomcat (AJP13)
worker.ankaisteel.port=8010
#这个名称一定要和tomcat的虚拟主机名配置成一样
Worker.ankaisteel.host=*****.com
Worker.ankaisteel.type=ajp13
Worker.ankaisteel.lbfactor=1
3. Let's configure Uriworkermap.properties
#这两个配置不是很确定, no tests, no two lines.
/*=ankaisteel
/*=worker3
4. Configuring Tomcat's Server.xml
At the back of the Server.xml, add:
Unpackwars= "true" autodeploy= "true"
Xmlvalidation= "false" Xmlnamespaceaware= "false" >
<context docbase= "/usr/local/tomcat/webapps/root" path= "" reloadable= "true"/>
</Host>
Unpackwars= "true" autodeploy= "true"
Xmlvalidation= "false" Xmlnamespaceaware= "false" >
<context docbase= "/usr/local/tomcat/webapps/company" path= "" reloadable= "true"/>
Here name must be consistent with the previous host, the path parameter must not write.
In summary, you can configure the success! Restart Apache and Tomcat to see the effect.
Go Apache+tomcat the same IP multi-domain multi-site configuration