实验环境
650) this.width=650;" src="https://s4.51cto.com/wyfs02/M01/A6/41/wKioL1nLdXvBmUy6AAAdBUBGmQk545.png" ?/>
提供两个基于名称的虚拟主机
wp.mykernel.cn
,页面文件目录为/web/vhosts/www1;错误日志为/var/log/httpd/www1.err,访问日志为/var/log/httpd/www1.access;www.mykernel.cn
, 页面文件目录为/web/vhosts/www2;错误日志为/var/log/httpd/www2.err,访问日志为/var/log/httpd/www2.access;为两个虚拟主机建立各自的主页文件index.html,内容分别为其对应的主机名;
通过wp.mykernel.com/server-status输出httpd工作状态相关信息,且只允许提供帐号密码才能访问(status:status);
为上面的
第2个
虚拟主机提供https
服务,使得用户可以通过https安全的访问此web站点;要求使用证书认证,证书中要求使用的国家(CN)、州(ChengDu)、城市(ChengDu)和组织(MageEdu);
设置部门为Ops,主机名为
www.mykernel.cn
,邮件为admin@mykernel.cn;
基本配置<172.16.100.1
>
配置yum源
*挂载光盘#mkdir/media/cdrom#mount-r/dev/cdrom/media/cdrom*yum仓库配置#mv/etc/yum.repos.d/CentOS-Base.repo{,.bak}#vimCentOS-Base.repo[C6-media]name=BaserepoforCentOS6failovermethod=prioritybaseurl=file:///media/cdromgpgcheck=1gpgkey=file:///media/cdrom/RPM-GPG-KEY-CentOS-6enabled=1
安装
httpd-2.2
程序#yum-yinstallhttpd
启动服务<
172.16.100.1
>#servicehttpdstart
用
支持纯文本协议
客户端工具访问测试安装#yum-yinstallcurlelinkstelnet测试#curl-Ilocalhost#elinks--dumphttp://localhost#telnet172.16.100.180GET/HTTP/1.1Host:172.16.100.1
配置虚拟主机
准备DocumentRoot,及对应的index.html文件<
172.16.100.1
>#install-d/web/vhosts/www{1,2}/#echo"wp.mykernel.cn">/web/vhosts/www1/index.html#echo"www.mykernel.cn">/web/vhosts/www2/index.html
修改/etc/httpd/conf/httpd.conf配置文件<
172.16.100.1
>备份配置文件:#cp-v/etc/httpd/conf/httpd.conf{,.bak}在配置文件中修改并添加如下内容:#vim/etc/httpd/conf/httpd.conf#DocumentRoot"/var/www/html"NameVirtualHost*:80<VirtualHost*:80>ServerNamewp.mykernel.cnDocumentRoot/web/vhosts/www1ErrorLoglogs/wp.errCustomLoglogs/wp.accesscombined<Location/server-status>SetHandlerserver-statusOrderallow,denyallowfromallAuthTypeBasicAuthName"SecureType/Domain"AuthUserFile"conf.d/.htpasswd"Requireuserstatus</Location></VirtualHost><VirtualHost*:80>ServerNamewww.mykernel.cnDocumentRoot/web/vhosts/www2ErrorLoglogs/www.errCustomLoglogs/www.accesscombined</VirtualHost>退出配置文件后:#httpd-t#htpasswd-c-s/etc/httpd/conf.d/.htpasswdstatus#servicehttpdreload
在windows主机中测试,虚拟账号是否能正常登陆
手动添加解析条目
进入此文件C:\Windows\System32\drivers\etc,添加如下条目172.16.100.1wp.mykernel.cn172.16.100.1www.mykernel.cn
在浏览器中,输入URL,测试结果
http://wp.mykernel.cnhttp://www.mykernel.cnhttp://wp.mykernel.cn/server-status账号:status,密码:status
图片650) this.width=650;" src="https://s3.51cto.com/wyfs02/M01/A6/44/wKioL1nLrt6BpGUIAAA0GVU9TeE061.png" ?/>650) this.width=650;" src="https://s3.51cto.com/wyfs02/M01/A6/44/wKioL1nLrt6SVm7FAAAYGTQ8KaU927.png" ?/>
mod_ssl模块,实现加密通信
自建CA<
172.16.100.2
>#dir=/etc/pki/CA#touch$dir/index.txt#echo"01">$dir/serial#(umask077;opensslgenrsa-out$dir/private/cakey.pem2048)#opensslreq-new-x509-key$dir/private/cakey.pem-out$dir/cacert.pem-days7300(CN,Beijing,Beijing,MageEdu,Ops,ca.magedu.com,admin@mykernel.cn)
生成请求<
172.16.100.1
>#install-d/etc/httpd/ssl&&cd/etc/httpd/ssl#(umask077;opensslgenrsa-outhttpd.key2048)#opensslreq-new-keyhttpd.key-outhttpd.csr-days365(CN,Beijing,Beijing,MageEdu,Ops,www.mykernel.cn,admin@mykernel.cn)
提交请求PUSH<
172.16.100.1
>#scphttpd.csrroot@172.16.100.2:/tmp
验证并颁发证书<
172.16.100.2
>#opensslca-in/tmp/httpd.csr-out$dir/certs/www.mykernel.cn.crt-days365
获取证书PULL<
172.16.100.1
>#scproot@172.16.100.2:/etc/pki/CA/certs/www.mykernel.cn.crt.
安装mod_ssl模块<
172.16.100.1
>#yum-yinstallmod_ssl
修改/etc/httpd/conf.d/ssl.conf配置<
172.16.100.1
>备份配置文件:#cp-v/etc/httpd/conf.d/ssl.conf{,.bak}修改配置文件:#vim/etc/httpd/conf.d/ssl.conf<VirtualHost*:443>DocumentRoot"/web/vhosts/www2"ServerNamewww.mykernel.cnSSLEngineonSSLCertificateFile/etc/httpd/ssl/www.mykernel.cn.crtSSLCertificateKeyFile/etc/httpd/ssl/httpd.key退出配置文件:#httpd-t#servicehttpdrestart查看443端是否处于监听状态#ss-tnl
测试是否能正常访问
Linux主机测试<
172.16.100.2
>添加解析记录:#vim/etc/hosts172.16.100.1www.mykernel.cn#openssls_client-connectwww.mykernel.cn:443-CAfile/etc/pki/CA/cacert.pemNew,TLSv1.2/SSLv3
Windows主机测试
*将172.16.100.2中的公钥,导入至Windows中的受信任的证书颁发机构列表中访问https://www.mykernel.cn即可
650) this.width=650;" src="https://s5.51cto.com/wyfs02/M02/A6/45/wKioL1nLuASg7vDyAAIy_1zKEiE546.png" ?/>650) this.width=650;" src="https://s3.51cto.com/wyfs02/M01/07/93/wKiom1nLuMWQ_d13AABUbSQIgWQ925.png" ?/>
有问题反馈
在使用中有任何问题,欢迎反馈给我,可以用以下联系方式跟我交流
邮件:lccnx@foxmail.com
QQ: 2192383945
感激
本文由我表哥引导制作,在此留下QQ,博客
QQ: 2580259468
博客
650) this.width=650;" src="https://s3.51cto.com/wyfs02/M02/A6/45/wKioL1nLuWbCNpuIAABpHaLUCWY380.png" ?/>
本文出自 “Reading” 博客,请务必保留此出处http://sonlich.blog.51cto.com/12825953/1969289
httpd-2.2项目(虚拟主机、用户认证、私有网络安全实现)
原文地址:http://sonlich.blog.51cto.com/12825953/1969289