apache集成tomcat,并根据域名进行分发 屏蔽端口显示

时间:2021-03-02 15:24:51

注:这里仅考虑apache做跳转

1、首先保证 mod_jk.so 版本正确,根据apache和tomcat的版本去http://www.apache.org寻找合适的mod_jk。

下载后copy到 apache/modules/目录下。

 

2、apache/conf目录下增加jk.conf文件,如下:

 

# Load mod_jk
LoadModule jk_module modules/mod_jk.so
JkWorkersFile conf/workers.properties
#JkLogFile logs/mod_jk.log
#JkLogLevel info
NameVirtualHost *:80
<VirtualHost *:80>
  DocumentRoot D:/root1
  ServerName server1.apache1.org
  JkMount /* tomcat01
</VirtualHost>
<VirtualHost *:80>
  DocumentRoot D:/root2
  ServerName test2.apache1.org
  JkMount /* tomcat02
</VirtualHost>
<VirtualHost *:80>
  DocumentRoot D:/root3
  ServerName test1.apache1.org
  JkMount /* tomcat01
</VirtualHost
>

3、apache/conf目录下增加workers.properties,如下:

# ------------------------
# First tomcat server
# ------------------------
worker.tomcat01.port=9109
worker.tomcat01.host=localhost
worker.tomcat01.type=ajp13
# ------------------------
# Second tomcat server
# ------------------------
worker.tomcat02.port=9009
worker.tomcat02.host=localhost
worker.tomcat02.type=ajp13

4、修改apache/conf目录下http.conf

Include conf/jk.conf

 

最终效果,当输入server1.apache.org和test1.apache.org时所有的处理交给tomcat01处理。

当输入test2.apache.org是交给tomcat02处理