第一题
1,安装httpd服务,配置yum源
yum httpd -y
配置如图
2,开启httpd,关闭防火墙,配置ip地址
3,编辑httpd下的文件
[root@localhost yum.repos.d]# vim /etc/httpd/conf.d/vhost.conf
注意这里的ip时虚拟机的ip,下面就是配置我们的目录,并且给目录中的文件添加内容
[root@localhost ~]# mkdir /131 /132
[root@localhost www]# echo "小胖,你咋这么胖" > 131/index.html
[root@localhost www]# systemctl restart httpd
第二题
步骤基本上与上一题差不多,直接修改配置文件在重启httpd服务
[root@localhost yum.repos.d]# vim /etc/httpd/conf.d/vhost.conf
[ztx@localhost ~]$ vim /etc/hosts
同时window也进行修改
第三题
首先修改配置文件
[root@localhost yum.repos.d]# vim /etc/httpd/conf.d/vhost.conf
创建文件写入内容,重启httpd服务
[root@localhost /]# mkdir /usr/local/hehe
[root@www hehe]# echo "this is 131" > /usr/local/hehe/index.html
[root@www hehe]# systemctl restart httpd
``
第四题**
修改配置,添加用户
```bash
[root@localhost yum.repos.d]# vim /etc/httpd/conf.d/vhost.conf
创建文件,写入内容,添加用户,重启httpd
[root@www /]# mkdir /usr/local/maomao
[root@www /]# echo "this is maomao" > /usr/local/maomao/index.html
[root@www /]# htpasswd -c /etc/httpd/userfile abc
New password:
Re-type new password:
Adding password for user abc
[root@www /]# htpasswd /etc/httpd/userfile xyz
New password:
Re-type new password:
Adding password for user xyz
[root@www /]# systemctl restart httpd
综合练习
修改配置文件
[root@localhost yum.repos.d]# vim /etc/httpd/conf.d/vhost.conf
根据配置文件建立创建目录,并写入信息
[root@www ~]# mkdir /openlab/{student,data,money} -pv
mkdir: created directory '/openlab'
mkdir: created directory '/openlab/student'
mkdir: created directory '/openlab/data'
mkdir: created directory '/openlab/money'
[root@www ~]# echo "welcome to openlab" > /openlab/index.html
[root@www ~]# echo "student" > /openlab/student/index.html
[root@www ~]# echo "data" > /openlab/data/index.html
[root@www ~]# echo "money" > /openlab/money/index.html
添加用户
[root@www ~]# htpasswd -c /etc/httpd/userfile song
New password:
Re-type new password:
Adding password for user song
[root@www ~]# htpasswd /etc/httpd/userfile tian
New password:
Re-type new password:
Adding password for user tian
编辑配置文件(基于域名访问),并且重启httpd
[root@www ~]# vim /etc/hosts
[root@www ~]# systemctl restart httpd
https部分
装包
[root@localhost /]# yum install httpd -y
[root@localhost ztx]# yum install -y mod_ssl
关闭防火墙
[root@localhost ztx]# setenforce 0
[root@localhost ztx]# rpm -qa mod_ssl
配置文件
[root@localhost ztx]# vim /etc/httpd/conf.d/vhosts.conf
制作私钥,证书,重启服务测试
[root@localhost certs]# openssl req -newkey rsa:4096 -nodes -sha256 -keyout ../private/openlab.key -x509 -days 365 -out openlab.crt
创建用户
[root@localhost certs]# htpasswd -c /etc/httpd/users song
[root@localhost certs]# htpasswd /etc/httpd/users tian
创建目录
[root@localhost certs]# mkdir -p /www/openlab
[root@localhost certs]# mkdir -pv /openlab/student
[root@localhost certs]# mkdir -pv /openlab/data
[root@localhost certs]# mkdir -pv /openlab/money
写入信息
[root@localhost certs]# echo "Welcome to openlab!" > /www/openlab/index.html
[root@localhost certs]# echo "student" > /openlab/student/index.html
[root@localhost certs]# echo "data" > /openlab/data/index.html
[root@localhost certs]# echo "money" > /openlab/money/index.html
写入缓存条目
[root@localhost certs]# vim /etc/hosts
Windows也要同时修改
(C:\Windows\System32\drivers\etc\hosts)