案例一

 1.要求实现基于主机头的虚拟主机,IP均为192.168.1.25

 2.主站点为www.abc.com,主目录为/var/www/html,任何人都能访问;

 3.市场部站点为mkt.abc.com,主目录为/var/www/mkt,设置默认主页为mkt.html

身份验证:user1,user2可以通过身份验证访问mkt.abc.com,     

来源控制:只有192.168.1.30能访问,

4.技术部站点为tec.abc.com,主目录为/var/www/tec,设置默认主页为tec.html,要求只允许通过https访问。

案例拓扑图如下图:

linux web服务器案例详解 

具体步骤:

为了用域名访问web服务器,我们先安装DNS服务

[[email protected] Server]# rpm -ivh bind-9.3.6-4.P1.el5.i386.rpm

[[email protected] Server]# rpm -ivh bind-chroot-9.3.6-4.P1.el5.i386.rpm

[[email protected] Server]# rpm -ivh caching-nameserver-9.3.6-4.P1.el5.i386.rpm

2.切换到 /var/named/chroot/etc

3.复制主配置文件,并修改如下

[[email protected] etc]# cp -p named.caching-nameserver.conf named.conf

[[email protected] etc]# vim named.conf

linux web服务器案例详解 

4.编辑named.rfc1912.zones文件

linux web服务器案例详解

5.切换目录,并拷贝域文件进行修改  (注意cp时要加上 -p

[[email protected] etc]# cd ../var/named

[[email protected] named]# cp -p localhost.zone  abc.com.zone

[[email protected] named]# vim abc.com.zone

linux web服务器案例详解

6.DNS服务器配置完成 重启 [[email protected] named]# service named restart

7.安装httpd服务

[[email protected] ~]# yum install httpd  -y

8.按照要求分别在/var/www/ 下建立对应的文件和目录

[[email protected] www]# echo "hello abc ! ! ! " >html/index.html

[[email protected] www]# echo "hello mkt ! ! ! " >mkt/mkt.html

[[email protected] www]# echo "hello tec ! ! ! " >tec/tec.html

9.修改http的主配置文件/etc/httpd/conf/httpd.conf,光标移至最后修改如下

linux web服务器案例详解 

linux web服务器案例详解 

10.NamevirtualHost 该配置语句生效,如下(默认是972行)

linux web服务器案例详解 

11.重启httpd服务。

12./var/www/mkt/,编辑.htaccess文件

linux web服务器案例详解

13.生成身份验证用户 user1user2  第一次使用htpasswd命令时要加-c

linux web服务器案例详解 

14.查看已经添加的账户

[[email protected] mkt]# tail .htpasswd 

user1:BXsAHqSlVNlPs

user2:3fELE9WN0ARFw

15.重启httpdnamed服务进行验证

案例中1-3中的要求,使用pc1访问ip192.168.1.30进行访问,注意:把防火墙关掉,默认DNS服务器的ip 192.168.1.25

linux web服务器案例详解 

linux web服务器案例详解 

linux web服务器案例详解 

16.使用pc2  ip地址为192.168.1.26测试

www.abc.com 可以访问而mkt.abc.com 则不行

linux web服务器案例详解 

 

下面来针对案例一中最后一项做ssl的访问配置

1.修改/etc/pki/tls/openssl.cnf的文件

linux web服务器案例详解 

 2.为了使申请证书的省市,不用完全匹配,将8890改为

optional

/88,90 s/match/optional /g

linux web服务器案例详解

3.填写申请证书可直接采用默认值,可对[req_distinguished_name]做如下修改:

linux web服务器案例详解 

4. 根据tls/openssl.cnf文件要求,生成三个目录,两个文件

[[email protected] CA]# mkdir crl certs newcerts

[[email protected] CA]# touch index.txt  serial

[[email protected] CA]# echo "01" >serial

5.openssl获得私钥

[[email protected] CA]# openssl genrsa 1024 >private/cakey.pem

[[email protected] CA]# chmod 600 private/*

6.用产生的私钥来生成证书

[[email protected] CA]# openssl req -new -key private/cakey.pem -x509 -out cacert.pem

linux web服务器案例详解

7.CA服务就配置完成,下面是web申请证书的过程,安装mod_ssl

[[email protected] CA]# yum install mod_ssl

8. 产生私钥,用产生的私钥生成证书

httpd目录下新建certs 目录

[[email protected] httpd]# mkdir certs

[[email protected] httpd]# cd certs

[[email protected] certs]# openssl genrsa 1024 >httpd.key

linux web服务器案例详解

请求

[[email protected] certs]# openssl req -new -key httpd.key -out httpd.csr

linux web服务器案例详解

颁发证书。

[[email protected] certs]# openssl ca -in httpd.csr -out httpd.cert

linux web服务器案例详解

9.修改/etc/httpd/conf.d/ssl.conf文件

linux web服务器案例详解 

10.修改  vim /etc/httpd/conf/httpd.conf 如下图

linux web服务器案例详解

 

11.修改vim /etc/httpd/conf.d/ssl.conf 文件如下

 11.修改vim /etc/httpd/conf.d/ssl.conf 文件如下

linux web服务器案例详解

 12重启httpd服务,pc1进行访问

先用http访问,结果访问不到

linux web服务器案例详解

在使用https访问

linux web服务器案例详解 

13.让其显示出根证书修改/etc/httpd/conf.d/ssl.conf 如下图

linux web服务器案例详解

14.查看证书,并安装证书

linux web服务器案例详解 

15.选择受信任的根证书颁发机构

linux web服务器案例详解 

16.目录可以ssl通过ssl正常访问了。

linux web服务器案例详解

 

转载于:https://blog.51cto.com/dg123/1034577

相关文章: