请选择段落导航
1.Tomcat 5 + Apache 2 + mod_jk 2 实现虚拟主机(1)
2.Tomcat 5 + Apache 2 + mod_jk 2 实现虚拟主机(2)
3.Tomcat 5 + Apache 2 + mod_jk 2 实现虚拟主机(3)
unpackWARs="true" autoDeploy="true">
<Alias>localhost</Alias>
<Alias>www</Alias>
<Alias>10.0.0.10</Alias>
<Context path="" docBase="" debug="1"/>
<Valve className="org.apache.catalina.valves.AccessLogValve"
directory="logs" prefix="vhost.vicp.net_access_log." suffix=".txt"
pattern="common" resolveHosts="false"/>
<Logger className="org.apache.catalina.logger.FileLogger"
directory="logs" prefix="home_log_" suffix="_app_log.txt"
timestamp="true"/>
</Host>[/code:1:141851c2a4]
调整里面的参数和设置使之适合你的环境,当然,如果你还有其他的<host/>添加在后面。
在 /usr/local/apache/conf 下面创建一个workers2.properties,内容如下:
[code:1:141851c2a4]#---- worker2.properties
[logger.apache2]
level=DEBUG
# Shared memory handling. Needs to be set.
[shm]
file=/usr/local/apache2/logs/shm.file
size=1048576
# Example socket channel, explicitly set port and host.
[channel.socket:localhost:8009]
tomcatId=localhost:8009
port=8009
host=127.0.0.1
# define the worker
[ajp13:localhost:8009]
channel=channel.socket:localhost:8009
#[status:status]
# Uri mapping
#[uri:/jkstatus/*]
#group=status:status
#[uri:/
jsp -examples/*]
#group=ajp13:localhost:8009
#[uri:/servlets-examples/*]
#group=ajp13:localhost:8009
#[uri:/
Java app/*]
#group=ajp13:localhost:8009
#[uri:www.home.net/*.
jsp ]
#worker=ajp13:localhost:8009
#[uri:10.0.0.10/*]
#worker=ajp13:localhost:8009
#---- end of workers2.properties[/code:1:141851c2a4]
当然,你可以删除其中的注释符使其中的uri和worker的配置生效,我现在不用这种方式配置是因为找到一个更好的方法:在httpd.conf里面配置:
把下面这段放到VirtualHost之前,可以从全局避免用户用apache访问WEB-INF目录。
[code:1:141851c2a4]<Directory ~ "/WEB-INF/">
Order allow,deny
Deny from all
</Directory>[/code:1:141851c2a4]
典型的VirtualHost配置样本
[code:1:141851c2a4]<VirtualHost _default_:80>
ServerName vhost.vicp.net
DocumentRoot /home/webapp/public_html/
DirectoryIndex index.htm index.html default.htm index.php index.
jsp <Location ~ "/*.
jsp |/*/servlet/*">
JkUriSet worker ajp13:localhost:8009
</Location>
ErrorLog logs/vhosts.vicp.net-err_log
CustomLog logs/vhosts.vicp.net-acc_log common
</VirtualHost>[/code:1:141851c2a4]
这样就可以为每个不同的虚拟主机分别指定使用或者不使用
jsp 功能。
好了,可以开始开发和使用你的web应用了!
参考文献:
1. http://jakarta.apache.org/tomcat/tomcat-4.1-doc/jk2/jk2/vhosthowto.html
2. http://bbs.china
unix .net/forum/6/20040214/259794.html
3. http://china
unix .net/jh/6/263220.html