例2:取消apache默认欢迎页:
[root@xuegod63 ~]# vim /etc/httpd/conf.d/welcome.conf
#
# This configuration file enables the default "Welcome"
# page if there is no default index page present for
# the root URL. To disable the Welcome page, comment
# out all the lines below.
#
# #把红色内容进行注释
# Options -Indexes
# ErrorDocument 403 /error/noindex.html
#
创建首页文件
[root@xuegod63 ~]# echo "Welcome to www.xuegod.cn" > /var/www/html/index.html
例4.修改网根目录及对应参数,设置访问权限 例: 设置文档目录为/var/www/html/bbs
目录与访问控制:
#子目录会继承这个目录的属性
Options FollowSymLinks #Options:Indexes:目录浏览 #Followsymlinks:可以用连接
AllowOverride None
Order allow,deny
Allow from 192.168.1.0/24 #从哪里来的允许
Deny from 192.168.1.0/24 #从哪里来的拒绝
Allow from .baidu.com
#Allow,Deny都会读取,如果有冲突和未说明的时候按照Order选项逗号后面的那个为准。
谁写到后面,谁的优先级高。
例7:通过用户认证的方式,对网站下/usr/local/phpmyadmin/目录进行保护。 设置/usr/local/phpmyadmin/目录,只能通过用户名密码方式访问。
方法一:
Alias /phpmyadmin/ "/usr/local/phpmyadmin/"
Options Indexes FollowSymLinks
AllowOverride None
Order deny,allow
Allow from all
authtype basic
authname "MySQL admin software......."
authuserfile /etc/httpd/conf/passwd.secret
#require user tom
#require user tom bob
require valid-user
生成认证账号和密码 [root@xuegod63 ~]# htpasswd -cm /etc/httpd/conf/passwd.secret rm New password: Re-type new password: Adding password for user rm 验证:
方法二:
[root@xuegod63 ~]# vim /etc/httpd/conf/httpd.conf
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
AllowOverride AuthConfig
# AllowOverride AuthConfig一行表示允许对/usr/local/phpmyadmin/目录下的文件进行用户认证。
[root@xuegod63 ~]# vim /usr/local/phpmyadmin/.htaccess
authtype basic
authname "MySQL admin software by .htaccess"
authuserfile /etc/httpd/conf/passwd.secret
#require user tom
require valid-user
利用Apache附带的程序htpasswd,生成包含用户名和密码的文本文
[root@xuegod63 ~]# htpasswd -cm /etc/httpd/conf/passwd.secret swk #指定用户
New password:
Re-type new password:
Adding password for user swk