cszer

Apache配置文件httpd.conf-2

分类: 技术, Apache   标签: , ,    评论: 0   阅读:2,060 views

一、.htaccess 与认证网页设定
建立保护目录的数据

[root@vps ~]# vim /etc/httpd/conf/httpd.conf
[root@vps ~]# echo "This is a test page" >index.html

修改httpd.conf文件:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 确定底下这几行是存在的
AccessFileName .htaccess
<files ~ "^\.ht">
    Order allow,deny
    Deny from all
    Satisfy All
</files>
 
# 加入这一段:
<directory "/var/www/html/protect">
    AllowOverride AuthConfig
    Order allow,deny
    Allow from all
</directory>

创建.htaccess文件

vim /var/www/html/.htaccess
AuthName     "Protect test by .htaccess"
Authtype     Basic
AuthUserFile /var/www/apache.passwd
require user test

参数说明:
* AuthName:在要你输入帐号与密码的对话框中的提示支付
* AuthType:认证的类型,我们这里仅列出 Apache 默认的类型,Basic
* AuthUserFile:这个保护目录所
* require:后面接可以使用的帐号。 如果要让该密码档内的使用者都能够登入,就改成’require valid-user’

创建密码文件:

[root@vps protect]# htpasswd -c /var/www/html/apache.passwd test
New password:
Re-type new password:
Adding password for user test

测试:
htaccess

二、虚拟主机配置:

主机名称                 对应的主目录
vhost1.cszhi.com   /var/www/vhost1
vhost2.cszhi.com   /var/www/vhost2

创建目录和网页文件:
[root@vps ~]# mkdir /var/www/vhost1
[root@vps ~]# mkdir /var/www/vhost2
[root@vps ~]# echo "vhost1.cszhi.com" >/var/www/vhost1/index.html
[root@vps ~]# echo "vhost2.cszhi.com" >/var/www/vhost2/index.html

编辑配置文件httpd.conf:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
NameVirtualHost *:80
 
#规范目录权限
<directory "/var/www/vhost1">
        Options FollowSymLinks
        AllowOverride None
        Order allow,deny
        Allow from all
</directory>
<directory "/var/www/vhost2">
        Options FollowSymLinks
        AllowOverride None
        Order allow,deny
        Allow from all
</directory>
 
#虚拟主机设置
<virtualHost *.80>
        ServerName vhost1.cszhi.com
        DocumentRoot    /var/www/vhost1
</virtualHost>
<virtualHost *.80>
        ServerName vhost2.cszhi.com
        DocumentRoot    /var/www/vhost2
</virtualHost>

测试访问:
virtualhost1

virtualhost2.png

除非注明,文章皆由( csz )原创,转载请标明本文地址
本文地址: http://www.cszhi.com/20120326/httpd-conf-2.html

03-26
2012

发表评论