题目:
1.要求搭建web服务器,能够访问到主页内容为“小胖,你咋这么胖呢!”
1)关闭防火墙
[root@localhost redhat]# systemctl stop firewalld
[root@localhost redhat]# setenforce 0
2)挂载
[root@localhost redhat]# mount /dev/sr0 /mnt
mount: /mnt: /dev/sr0 already mounted on /mnt.
3)安装包
[root@localhost redhat]# vim /etc/yum.repos.d/mnt.repo
[root@localhost redhat]# yum install httpd -y
4)创建文件夹
[root@localhost redhat]# mkdir /{xiaopang,dapang}
[root@localhost redhat]# mkdir /usr/local/haha
[root@localhost redhat]# mkdir /xiaopang/100
[root@localhost redhat]# echo "小胖,你怎么这么胖呢!" > /var/www/html/index.html
5)重启服务
[root@localhost redhat]# systemctl restart httpd
测试结果
2.要求搭建web服务器,创建基于域名的虚拟主机,能够使用www.xiaopang.com和www.dapang.com访问各自的网站网站存放路径分别为/xiaopang和/dapang,内容自定。
[root@localhost html]# vim /etc/httpd/conf.d/ip.conf
[root@localhost html]# mkdir /dapang
[root@localhost html]# mkdir /xiaopang
[root@localhost html]# systemctl restart httpd
[root@localhost html]# echo dapang > /dapang/index.html
[root@localhost html]# echo xiaopang > /xiaopang/index.html
测试结果:
3.创建虚拟目录真实物理位置在 /usr/local/maomao,内容自定,但允许abc和xyz用户通过密码访问,定义基于域名访问的网站的配置文件
vim /etc/httpd/conf.d/vhosts.conf
<VirtualHost 192.168.125.128:80>
ServerName 192.168.125.128
DocumentRoot "/usr/local"
Alias /hehe /usr/local/hehe
</VirtualHost>
<Directory /usr/local>
AllowOverride none
Require all granted
</Directory>
创建文件
[root@localhost ~]# mkdir /usr/local/hehe
[root@localhost ~]# echo this is haha >/usr/local/hehe/index.html
修改默认文件的权限,使其他用户具有读和执行权限
cd /usr/local/hehe
chmod 705 index.html
修改httpd.conf文件
vim /etc/httpd/conf.d/httpd.conf
Alias /hehe "/usr/local/hehe"
<Directory "/usr/local/hehe">
Options Indexes MultiViews
AllowOverride none
order allow,deny
Allow from all
</Directory>
重启服务[root@localhost ~]# systemctl restart httpd
运行结果:
4.创建虚拟目录真实物理位置在/usr/local/maomao,内容自定,但允许abc和xyz用户通过密码访问。
mkdir /usr/local/MAOMAO
echo this is aba xyz > /usr/local/MAOMAO/index.html
htpasswd -c /etc/httpd/usr abc
htpasswd /etc/httpd/usr xyz
修改默认文件的权限
chmod 705 index.html
修改文件vim /etc/httpd/conf.d/httpd.conf
Alias /MAOMAO "/usr/local/MAOMAO"
<Directory "/usr/local/MAOMAO">
Options Indexes MultiViews
AllowOverride none
order allow,deny
Allow from all
</Directory>
vim /etc/httpd/conf.d/vhosts.conf
<VirtualHost 192.168.125.128:80>
ServerName 192.168.125.128
DocumentRoot /usr/local/MAOMAO
</VirtualHost>
<Directory /usr/local/MAOMAO>
AuthType Basic
AuthName "Please login:"
AuthuserFile /etc/httpd/usr
Require user abc xyz
</Directory>
systemctl restart httpd
运行结果:
综合练习:请给openlab搭建web网站
网站需求:
1.基于域名www.openlab.com可以访问网站内容为 welcome to openlab!!!
2.给该公司创建三个虚拟网站目录分别显示学生信息,教学资料和缴费网站,基于www.openlab.com/student 网站访问学生信息,www.openlab.com/data网站访问教学资料
www.openlab.com/money网站访问缴费网站。
3.要求(1)学生信息网站只有song和tian两人可以访问,其他网站所有用户用能访问。
(2)访问缴费网站实现数据加密基于https访问。
systemctl stop firewalld 关闭防火墙
setenforce 0 关闭selinux防火墙
vim /etc/httpd/conf.d/openlab.conf
<Directory /openlab>
AllowOverride none
Require all granted
</Directory>
<VirtualHost 192.168.125.128:80>
DocumentRoot /openlab
ServerName www.openlab.com
Alias /student /1
Alias /data /2
</VirtualHost>
<VirtualHost 192/168.125.128:443>
Alias /money /3
ServerName www.openlab.com
DocumentRoot /3
SSLEngine on
SSLCertificateFile /etc/pki/tls/certs/openlab.crt
SSLCertificateKeyFile /etc/pki/tls/private/openlab.key
</VirtualHost>
<Directory /1>
AuthType basic
AuthName "please login"
AuthUserFile /etc/httpd/users
Require user /song tian
</Directory>
<Directory /2>
AllowOverride none
Require all granted
</Directory>
<Directory /3>
AllowOverride none
Require all granted
</Directory>
给windows和linux的hosts加上192.168.125.128 www.openlab.com
mkdir /openlab
mkdir /1 /2 /3
echo Welcome to openlab !!! > /openlab/index.html
echo 欢迎访问学生信息 > /1/index.html
echo 欢迎访问教学资料 > /2/index.html
echo 欢迎访问缴费页面 > /3/index.html
增加用户song tian
htpasswd -c /etc/httpd/users song
htpasswd /etc/httpd/users tian
安装SSL加密包 dnf install mod-ssl -y
cd /etc/pki/tls/certs
制作安全证书
openssl req -utf8 -newkey rsa:4096 -nodes -sha256 -keyout openlab.key -x509 -days 356 -out openlab.crt
移动目录mv openlab.key ../private/
systemctl restart httpd
运行结果: