http 实战练习
http 实战练习
建立httpd服务器,要求提供两个基于名称的虚拟主机:
(1)www.X.com,页面文件目录为/web/vhosts/x;错误日志为/var/log/httpd/x.err,访问日志为/var/log/httpd/x.access
(2)www.Y.com,页面文件目录为/web/vhosts/y;错误日志为/var/log/httpd/www2.err,访问日志为/var/log/httpd/y.access
(3)为两个虚拟主机建立各自的主页文件index.html,内容分别为其对应的主机名
(4)通过www.X.com/server-status输出httpd工作状态相关信息
#增加两条HOST 解析
vim /etc/hosts
192.168.120.130 www.x.com www.y.com
vim /etc/httpd/conf.d/vhost.conf
<VirtualHost *:80>
#虚拟主机的别名;可多次使用,目前是不起作用的
ServerName www.x.com
#指定根目录
DocumentRoot "/web/vhosts/x"
#错误日志
ErrorLog "logs/x.err"
#访问日志
TransferLog "logs/x.access"
<Location /server-status>
SetHandler server-status
Order deny,allow
Deny from all
Allow from 192.168
</Location>
</VirtualHost>
<VirtualHost *:80>
#虚拟主机的别名;可多次使用,目前是不起作用的
ServerName www.y.com
#指定根目录
DocumentRoot "/web/vhosts/y"
#错误日志
ErrorLog "logs/www2.err"
#访问日志
TransferLog "logs/y.access"
</VirtualHost>
<Directory "/web/vhosts">
Order allow,deny
Allow from all
</Directory>
如果是Centos6 一定要把主配置文件中的NameVirtualHost 打开,或者在这个配置文件中加上以下配置
NameVirtualHost *:80
否则无法启动虚拟主机!!!!
2、为上面的第2个虚拟主机提供https服务,使得用户可以通过https安全的访问此web站点
(1)要求使用证书认证,证书中要求使用的国家(CN)、州(Beijing)、城市(Beijing)和组织(MageEdu)
(2)设置部门为Ops,主机名为www.Y.com,邮件为admin@Y.com
省略步骤 参考 http 高级配置 笔记中的步骤
注意:ssl会话只能基于IP创建,这意味着如果服务器仅有一个IP,那么仅为一个虚拟主机提供https服务
编译安装httpd-2.4 使用httpd-2.4实现
1、建立httpd服务,要求:
(1) 提供两个基于名称的虚拟主机:
www.a.com
页面文件目录为/web/vhosts/www1
错误日志为/var/log/httpd/www1/error_log
访问日志为/var/log/httpd/www1/access_log
www.b.com
页面文件目录为/web/vhosts/www2
错误日志为/var/log/httpd/www2/error_log
访问日志为/var/log/httpd/www2/access_log
(2) 通过www.a.com/server-status输出其状态信息,且要求只允许提供账号的用户访问
(3) www.a.com不允许192.168.1.0/24网络中的主机访问
编译安装httpd-2.4
#一次性编译安装 apr + apr-util + http 不需要分三次来
#把三个压缩包都解压了
yum groupinstall Development Tools,Server
yum install openssl-devel expat-devel pcre-devel
useradd -r -g 80 apache
useradd -r -s /sbin/nologin -u 80 -g 80 apache
tar xvg apr apr-util httpd
mv apr-1.6.3 http/srclib/apr
mv apr-util-1.6.1 http/srclib/apr-util
cd httpd-2.4.27/
./configure --prefix=/app/httpd24 --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-included-apr --enable-modules=most --enable-mpms-shared=all --with-mpm=prefork
make && make install
#添加变量
echo PATH=/app/httpd24/bin:$PATH > /etc/profile.d/httpd.sh
#启动服务
apachectl
设置虚拟主机
#创建验证文件
htpasswd -s -c .httpuser ddz
htpasswd -s .httpuser wang
#虚拟主机设置
vim /app1/httpd24/conf/http.conf
Include conf/conf.d/*.conf
vim /app1/httpd24/conf/conf.d/vhost.conf
<VirtualHost *:80>
ServerName www.a.com
DocumentRoot "/web/vhosts/www1"
ErrorLog "/var/log/httpd/www1/error_log"
TransferLog "/var/log/httpd/www1/access_log"
<Location /server-status>
SetHandler server-status
AuthType Basic
AuthName "Please Input Accout!!!"
AuthUserFile "/appl/httpd24/conf/conf.d/.httpuser"
Require user ddz,wang
</Location>
<Directory "/web/vhosts/www1">
<RequireAll>
Require all granted
Require not ip 192.168.1.
</RequireAll>
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName www.b.com
DocumentRoot "/web/vhosts/www2"
ErrorLog "/var/log/httpd/www2/error_log"
TransferLog "/var/log/httpd/www2/access_log"
</VirtualHost>
2、为上面的第2个虚拟主机提供https服务,使得用户可以通过https安全的访问此web站点
(1) 要求使用证书认证,证书中要求使用国家(CN),州(Beijing),城市(Beijing),组织为(MageEdu)
(2) 设置部门为Ops, 主机名为www.b.com
如果是编译安装,安装完模块,需要移动配置文件
yum install mod_ssl
cp /etc/httpd/conf.d/ssl.conf /appl/httpd24/conf/conf.d/ssl.conf
开启模块
vim httpd.conf
LoadModule ssl_module modules/mod_ssl.so
LoadModule socache_shmcb_module modules/mod_socache_shmcb.so
配置SSL文件
<VirtualHost 192.168.120.131:443>
DocumentRoot "/web/vhosts/www1"
ServerName www.a.com
SSLCertificateFile /appl/httpd24/certs/httpd.crt
SSLCertificateKeyFile /appl/httpd24/certs/httpd.key
SSLCertificateChainFile /etc/pki/CA/cacert.pem
使用了https的话,记得把刚才vhost里面的虚拟主机配置移动到ssl中,否则无法识别。
ssl 是可以配置多个的
最新文章
- asp.net 无法加载程序集***
- shell统计指定范围内的所有质数以及它们的和
- 涨知识Style
- Camel、Pastal、匈牙利标记法
- [Everyday Mathematic]20150216
- Linux 输入子系统
- ckeditor增加上传图片的功能
- hdu4010-Query on The Trees(lct分裂合并加值查询最大值)
- 百度ueditor富文本编辑器的使用
- web前端与后端
- Hall定理 二分图完美匹配
- Android进阶推荐书籍
- Bootstrap -- 网格系统、排版样式类、 <;blockquote>;、 <;abbr>; 元素
- No module named HTMLTestRunner
- centos 6.5环境利用iscsi搭建SAN网络存储服务及服务端target和客户端initiator配置详解
- Ubuntu中apt与apt-get命令的区别
- Phpcms V9单页添加自定义字段
- c# 、 Asp.net 获取本地IP和MAC地址
- 160407、java实现多线程同步
- mapper配置文件中的动态SQL