Tomcat虚拟主机的安全配置
由Tomcat构建支持JSP的虚拟主机,目录结构如下:
D:\wwwroot
├host1
│ ├html
│ ├webapps
│ └logs
└host2
├html
├webapps
└logs
Tomcat的配置文件相关内容如下:
<Host name="host1" debug="0" appBase="d:\wwwroot\host1\webapps" unpackWARs="true" autoDeploy="true">
<Context path="" docBase="d:\wwwroot\host1\html" debug="0"/>
</Host>
<Host name="host2" debug="0" appBase="d:\wwwroot\host2\webapps" unpackWARs="true" autoDeploy="true">
<Context path="" docBase="d:\wwwroot\host1\html" debug="0"/>
</Host>
在$CATALINA_HOME/conf/catalina.policy文件中增加以下内容:
grant codeBase "file:d:\wwwroot\host1\-" {
permission java.io.FilePermission "file:/www/hosts/host1/-", "write";
};
grant codeBase "file:d:\wwwroot\host1\-" {
permission java.io.FilePermission "file:d:\wwwroot\host1\-", "write";
};
OK,用以下命令启动Tomcat
$CATALINA_HOME/bin/catalina.bat start -security
此时虚拟主机host1中的JSP/servlet只能够修改d:\wwwroot\host1目录下的文件,虚拟主机host2中的JSP/servlet只能够修改d:\wwwroot\host2目录下的文件,从而达到隔离各个虚拟主机的目的。
以上内容仅在本机测试通过(Win2003 pro + Tomcat 6.0.20)。