鹅鹅根据相关要求搭建
临时关闭防火墙和selinux
[root@localhost etc]# systemctl stop firewalld
[root@localhost etc]# setenforce 0
一 练习题
1.搭建web服务器,访问到 "小胖,你咋这么胖"
/etc/httpd/conf.d 子配置目录(自定义的配置文件)
在vim etc/httpd/conf.d/fhosts.d 进行配置
<virtualHost 192.168.171.129>
DocumentRoot "/fast/129"
ServerName 192.168.171.129
</virtualHost>
<Directory /fast>
AllowOverride none
Require all granter
</Directory>
mkdir /fast/129
echo 小胖,你咋这么胖 > /fast/129/index.html
systemctl restart httpd
访问成功了!!!
2.创建基于域名的的虚拟主机
继续在原配置中做修改ewe1e1
<virtualHost 192.168.171.129>
DocumentRoot "/xiaopang"
ServerName www.xiaopang.com
</virtualHost>
<virtualHost 192.168.171.129>
DocumentRoot "/dapang"
ServerName www.dapangpang.com
</virtualHost>
<Directory /xiaopang>
AllowOverride none
Require all granted
</Directory>
<Directory /dapang>
AllowOverride none
Require all granted
</Directory>
mkdir /xiaopang
mkdir /dapang
echo i am big fat > /dapang/index.html
echo i am small fat > /dapang/index.html
systemctl restart httpd
注意:域名访问需要在文件下面注册
成功了!!
3.创建虚拟目录
<virtualHost 192.168.171.129>
DocumentRoot "/xiaopang"
Alias /x /xiaopang/129
ServerName 192.168.171.129
</virtualHost>
<Directory>
AllowOverride none
Require all granted
</Directory>
mkdir /xiaopang/129
echo i am 129 > /xiaopang/129/index.html
systemctl restart httpd
成功访问!!!!
4.创建虚拟网络,允许abc和xyz访问
<v<virtualHost 192.168.171.129>
DocumentRoot "/xiaopang"
Alias /x /xiaopang/129
ServerName 192.168.171.129
</virtualHost>
<Directory /xiaopang>
AllowOverride none
Require all granted
</Directory>
<Directory /xiaopang/129>
AuthType Basic
AuthName "please login:"
AuthuserFile /etc/httpd/userfile
Require user abc xyz
</Directory>
成功了!!
5.真题
<virtualHost 192.168.171.129>
DocumentRoot "/xiaopang"
Alias /student /xiaopang/student
Alias /data /xiaopang/data
Alias /moeny /xiaopang/money
ServerName 192.168.171.129
</virtualHost>
<Directory /xiaopang>
AllowOverride none
Require all granted
</Directory>
<Directory /xiaopang/student>
AuthType Basic
AuthName "please login:"
AuthuserFile /etc/httpd/userfile
Require user song tian
</Directory>
<VirtualHost 192.168.171.129>
DocumentRoot "/xiaopang/money"
ServerName 192.168.171.129
SSLEngine on
SSLCertificateFIle /etc/pki/tls/certs/openlab.crt
SSLCertificateKeyFile /etc/pki/tls/private/openlab.key
</Virtualhost>
设置song和tian的密码
htpasswd -c /etc/httpd/userfile song
Adding password for user song
htpasswd -c /etc/httpd/userfile tian
Adding password for user tian
添加用户数据
echo this is a stydent! > /xiaopang/student/index.html
echo this is a data! > /xiaopang/data/index.html
echo this is money! > /xiaopang/money/index.html
搭建https加密
cd /etc/pki/tls/certs
openssl req -newkey rsa:4096 -nodes -sha256 -keyout ../private/openlab.key -x509 -days 365 -out openlab.crt