我们就可以通过设置用户认证和实现https加密传输的实验来配置httpd了,下面是本次实验的要求:
实验环境:
CentOS release6.6(Final) 1台
Windows XP 1台
IP地址:
172.16.31.31 www.stu31.com web服务器端
172.16.31.188 Windows XP测试客户端
Windows XP安装了chrom浏览器和系统自带的IE浏览器
软件版本:
httpd-2.2.15-39.el6.centos.x86_64
实验要求:
1、建立httpd服务器,要求:
提供两个基于名称的虚拟主机:
(a)www1.stu31.com,页面文件目录为/web/vhosts/www1;错误日志为/var/log/httpd/www1.err,访问日志为/var/log/httpd/www1.access;
(b)www2.stu31.com,页面文件目录为/web/vhosts/www2;错误日志为/var/log/httpd/www2.err,访问日志为/var/log/httpd/www2.access;
(c)为两个虚拟主机建立各自的主页文件index.html,内容分别为其对应的主机名;
(d)通过www1.stu31.com/server-status输出httpd工作状态相关信息,且只允许提供帐号密码才能访问(status:status);
2、为上面的第2个虚拟主机提供https服务,使得用户可以通过https安全的访问此web站点;
(1)要求使用证书认证,证书中要求使用的国家(CN)、州(Henan)、城市(Zhengzhou)和组织(stu31);
(2)设置部门为tech,主机名为www2.stu31.com,邮箱为admin@stu31.com;
实验过程:
我们就通过rpm包的方式来安装httpd了,安装过程很简单;重要的是配置:
[root@www ~]# rpm-qa httpd
httpd-2.2.15-39.el6.centos.x86_64
1、建立httpd服务器(基于编译的方式进行),要求:
提供两个基于名称的虚拟主机:
(a)www1.stu31.com,页面文件目录为/web/vhosts/www1;错误日志为/var/log/httpd/www1.err,访问日志为/var/log/httpd/www1.access;
(b)www2.stu31.com,页面文件目录为/web/vhosts/www2;错误日志为/var/log/httpd/www2.err,访问日志为/var/log/httpd/www2.access;
(c)为两个虚拟主机建立各自的主页文件index.html,内容分别为其对应的主机名;
(d)通过www1.stu31.com/server-status输出httpd工作状态相关信息,且只允许提供帐号密码才能访问(status:status);
一.配置DNS服务器,为客户端提供域名解析服务。
主配置文件配置:
[root@www ~]# cat/etc/named.conf
//
// named.conf
//
// Provided by RedHat bind package to configure the ISC BIND named(8) DNS
// server as acaching only nameserver (as a localhost DNS resolver only).
//
// See/usr/share/doc/bind*/sample/ for example named configuration files.
//
options {
// listen-on port 53 { 127.0.0.1; };
// listen-on-v6 port 53 { ::1; };
directory"/var/named";
dump-file"/var/named/data/cache_dump.db";
statistics-file"/var/named/data/named_stats.txt";
memstatistics-file"/var/named/data/named_mem_stats.txt";
// allow-query { localhost; };
recursion yes;
// dnssec-enable yes;
// dnssec-validation yes;
// dnssec-lookaside auto;
/* Path to ISC DLV key */
/*bindkeys-file"/etc/named.iscdlv.key";
managed-keys-directory"/var/named/dynamic";
*/
};
logging {
channel default_debug {
file"data/named.run";
severity dynamic;
};
};
zone "."IN {
type hint;
file "named.ca";
};
include"/etc/named.rfc1912.zones";
include "/etc/named.root.key";
区域文件配置,加入stu31.com这个区域:
区域解析库文件配置:
测试DNS服务器可用性:
二.Httpd服务器配置
创建网站目录及加入测试网页:
配置httpd的主配置文件/etc/httpd/conf/httpd.conf,我列出了主要配置:
[root@www named]#vim /etc/httpd/conf/httpd.conf
#DocumentRoot"/var/www/html"
NameVirtualHost172.16.31.31:80
<VirtualHost172.16.31.31:80>
DocumentRoot /web/vhosts/www1
ServerName www1.stu31.com
ErrorLog"/var/log/httpd/www1.err"
CustomLog"/var/log/httpd/www1.access"combind
<Location/server-status>
SetHandler server-status
Authtype Basic
Authname "status area"
AuthUserFile /etc/httpd/users/.htpasswd
Require valid-user
</Location>
</VirtualHost>
<VirtualHost172.16.31.31:80>
DocumentRoot /web/vhosts/www2
ServerName www2.stu31.com
ErrorLog"/var/log/httpd/www2.err"
CustomLog"/var/log/httpd/www2.access" combind
</VirtualHost>
上面蓝色部分配置是用户认证配置,下面我们需要检查语法:
针对用户认证配置,我们需要建立用户访问的认证用户文件:
完成后我们就可以启动httpd服务,来进行用户认证测试:
三.用户认证测试:
输入用户名和密码认证:
可以查看apache服务器状态信息:
2、为上面的第2个虚拟主机提供https服务,使得用户可以通过https安全的访问此web站点;
(1)要求使用证书认证,证书中要求使用的国家(CN)、州(Henan)、城市(Zhengzhou)和组织(stu31);
(2)设置部门为tech,主机名为www2.stu31.com,邮件为admin@stu31.com;
HTTPS加密传输配置过程
(a)建立私有CA认证服务器
[root@www named]# cd /etc/pki/CA/
#构建CA自有私钥文件
#生成自签署证书
#生成索引数据库文件
#序列号文件创建
CA服务器建立完毕。
(b)为httpd服务器生成证书
#httpd服务器生成私钥
#生成证书签署请求文件
(c)配置httpd服务使用数字证书
#CA服务器签署请求证书
(d)配置https服务器加密传输
针对Apache httpd软件默认配置中:
httpd软件默认没有使用ssl模块,需要安装相应的模块程序包
安装之后会在/etc/httpd/conf.d/目录下生成ssl.conf的配置文件,我们配置https就在此文件中配置:
配置ssl.conf文件,重要配置都在下面文件中了:
测试文件语法:
重启httpd服务
查看服务监听端口:
到windows端进行测试:
先将CA服务器的证书安装进windows中;将cacert.pem发送到windows中,改名cacert.crt,安装证书:
使用chrom浏览器进行测试
实验完成!(*^__^*)