RHCE----http服务练习
要求
1.基于域名访问网站
1.安装httpd包
dnf install httpd -y
2。编辑配置文件
vim /etc/httpd/conf.d/host.conf
<VirtualHost 192.168.155.31:80>
DocumentRoot /openlab/chi
ServerName www.openlab.com
</VirtualHost>
<Directory /openlab/chi>
Allowoverride none
Require all granted
</Directory>
3.本地域名解析
vim /etc/hosts
ip 域名(192.168.155.31 www.openlab.com)
4.创建网页
mkdir /openlab/chi/index.html
echo 'welcome to openlab!!!' > /openlab/chi/index.html
5.关闭防火墙和selinux
systemctl stop firewalld
setenforce 0
6.重启http服务
systemctl restart httpd
测试
2.按要求创建网页子目录
mkdir /openlab/chi/{student,data,money}
echo tian的学生信息 > /openlab/chi/student/index.html
echo 教学资料 > /openlab/chi/data/index.html
echo 缴费信息 > /openlab/chi/wang/money/index.html
根据要求1:实现用户访问控制
编辑配置文件 vim /etc/httpd/conf.d/host.cof
添加: <Directory /openlab/chi/student>
Authtype basic
Authname "用户名:"
AuthUserFile /etc/httpd/users
Require user tian song
</Directory>
创建用户
htpasswd -c /etc/httpd/users tian //-c 表示创建目录同时添加用户
htpasswd /etc/httpd/users song
修改过配置文件后要重启服务
systemctl restart httpd
测试
根据要求2:实现基于https协议的数据加密
1.安装mod_ssl包
dnf install mod_sll -y
2.创建密钥文件
/usr/bin/openssl genrsa -aes128 2048 > /etc/pki/tls/private/miyao.key
Generating RSA private key, 2048 bit long modulus (2 primes)
.+++++
......................................................................................+++++
e is 65537 (0x010001)
Enter pass phrase: //自定义新密码,不填则为空
Verifying - Enter pass phrase: //确认密码,不填则确认为空
3.创建公钥文件
openssl req -utf8 -new -key /etc/pki/tls/private/miyao.key -x509 -days 365 -out /etc/pki/tls/certs/zhengshu.crt
4.编辑配置文件 vim /etc/httpd/conf.d/host.cof
添加: <VirtualHost 192.168.155.31:443>
DocumentRoot /openlab/chi/wang 基于协议不同,区分主目录
SSLEngine on
SSLCertificateFile /etc/pki/tls/certs/zhengshu.crt
SSLCertificateKeyFile /etc/pki/tls/private/miyao.key
</VirtualHost>
修改过配置文件后要重启服务
systemctl restart httpd
测试