apache用户验证与虚拟主机包括整合tomcat的虚拟主机
时间:2005-09-09 来源:sword_111
apache用户验证与虚拟主机包括整合tomcat的虚拟主机
2)用户验证
<Directory "/www/htdocs/www1">
Authname "www1"
AuthType Basic
AuthUserFile /www/pwd/userpwd (此处为用户验证的密码文件的位置)
Require user www1 (此处为要验证的用户名,多个用户可以用空格间隔)
</Directory>
<Directory "/www/htdocs/www2">
Authname "www2"
AuthType Basic
AuthUserFile /www/pwd/userpwd
Require user www2
</Directory>
<Directory "/www/htdocs/www3">
Authname "www3"
AuthType Basic
AuthUserFile /www/pwd/userpwd (此处为用户验证的密码文件的位置)
AuthGroupFile /www/pwd/groupfile (此处为用户验证的组文件的位置)
Require group test (此处为用户验证的组名)
</Directory>
然后再apache的安装目录下的bin目录里运行
./htpasswd -c /www/pwd/userpwd www1
New password:
Re-type new password:
Adding password for user www1
添加一个用户www1并创建userpwd文件
./htpasswd /www/pwd/userpwd www2
添加用户www2注意此处没用-c否则将覆盖掉原来的文件丢失www1的信息
创建组
在组文件所在的目录里
Vi groupfile (创建组文件)
我的内容为
test: www1 www2 (用户名之间用空格隔开组名冒号后的第一个用户名也要与冒号用空格隔开)
2)虚拟主机未整合tomcat
NameVirtualHost 192.168.0.100
<VirtualHost 192.168.0.100:80>
ServerName www.sword.net (域名)
ServerAlias sword.net *.sword.net (此处我也不不太明白,请高手指教)
DocumentRoot /www/htdocs/ (网站根目录所在的位置)
</VirtualHost>
<VirtualHost 192.168.0.100:80>
ServerName test.net.henkel
DocumentRoot /www/htdocs/www2
</VirtualHost>
此两个为域名解析注意要在dns作相应的设置才能使用:)
相关文档http://man.chinaunix.net/newsoft/ApacheManual/
<VirtualHost 192.168.0.100:81>
ServerAdmin [email protected]
DocumentRoot /www/htdocs/www1
ServerName sword.com
ErrorLog logs/sword.com-error_log
CustomLog logs/sword.com-access_log common
</VirtualHost>
<VirtualHost 192.168.0.100:82>
ServerAdmin [email protected]
DocumentRoot /www/htdocs/www2
ServerName sword.com
ErrorLog logs/sword.com-error_log
CustomLog logs/sword.com-access_log common
</VirtualHost>
<VirtualHost 192.168.0.101:80>
ServerAdmin [email protected]
DocumentRoot /www/htdocs/www3
ServerName sword.com
ErrorLog logs/sword.com-error_log
CustomLog logs/sword.com-access_log common
</VirtualHost>
以上是基于ip的虚拟主机设置,最后的192.168.0.101:80是虚拟ip的主机设置。
基于tomcat的虚拟主机
<VirtualHost 192.168.0.100:83>
ServerAdmin [email protected]
DocumentRoot /www/www
DirectoryIndex index.jsp index.htm index.html index.php (此处应该能改更改默认主页,但不知道为什么我更改了几次都没有成功,请高手指教,是不是要把前面的DirectoryIndex注释电掉?)
ServerName sword.com
ErrorLog logs/sword.com-error_log
CustomLog logs/sword.com-access_log common
(此下三行为在虚拟主机中调用jsp的解析程序,我是这样认为的,如有不妥之处请高手指点)
<Location "/*.jsp">
JkUriSet worker ajp13:localhost:8009
</Location>
</VirtualHost>
修改tomcat安装目录下的/conf/server.xml在server.xml中的
<Engine> </Engine>中添加
<Host name="192.168.0.100" debug="0" (确定ip或域名)
appBase="/www/www"(确定主目录)
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="vtomcat_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>
参考文献http://jakarta.apache.org/tomcat/tomcat-4.1-doc/jk2/jk2/vhosthowto.html