实验 4 :建立两个基于域名访问的网站,要求如下:
新建一个网站,域名为 www.ceshi.com ,设置网站首页目录为 /www/name ,网页内容为 this is
test 。
新建一个网站,域名为 rhce.first.day ,同时可通过 ce.first.day 访问,设置网站首页目录
为 /www/ce, 网页内容为: today is first day of class 。
![](https://i-blog.csdnimg.cn/direct/526ac25853c346f297efdfe90a52c429.png)
![](https://i-blog.csdnimg.cn/direct/65485933ae1f4642a0c5d724c5c0999e.png)
![](https://i-blog.csdnimg.cn/direct/1c5f728e7b294ab39fd8e14657b7aca6.png)
![](https://i-blog.csdnimg.cn/direct/c60070d67dae44eeb89d16aded0ecc51.png)
![](https://i-blog.csdnimg.cn/direct/b929541b202f4e0bbbb8feaee076122d.png)
![](https://i-blog.csdnimg.cn/direct/8c4619d5e8c245ffb3b02b475650c23b.png)
![](https://i-blog.csdnimg.cn/direct/51990af75e994b728cc72159d7af5e0c.png)
重启
![](https://i-blog.csdnimg.cn/direct/bb4846a64e37404788f2586655c76554.png)
![](https://i-blog.csdnimg.cn/direct/c77e6d3b35ab40ab98ace8b474ecef31.png)
![](https://i-blog.csdnimg.cn/direct/3ff5c6b7ca284f59bbe1baf6a2409999.png)
实验 5 :基于虚拟目录和用户控制的 web 网站
# 虚拟目录实现
[root@localhost conf.d] # nmcli connection modify ens33 +ipv4.addresses
192.168.231.103/24
[root@localhost conf.d] # nmcli connection up ens3160
[root@localhost ~] # vim /etc/nginx/conf.d/test_virtualdir.conf
server {
listen 192 .168.231.103:80;
root /usr/share/nginx/html;
location /real {
alias /www/real;
}
}
[root@localhost ~] # mkdir /www/real/
[root@localhost ~] # echo real-virtual > /www/real/index.html
[root@localhost ~] # systemctl restart nginx
[root@localhost ~] # curl 192.168.231.103/real/
real-virtual
# 用户访问控制
[root@localhost ~] # vim /etc/nginx/conf.d/test_virtualdir.conf
server {
listen 192 .168.168.155:80;
root /usr/share/nginx/html;
location /real {
alias /www/real;
auth_basic on;
auth_basic_user_file /etc/nginx/conf.d/auth-password;
}
}
[root@localhost ~] # dnf install httpd-tools -y
[root@localhost ~] # htpasswd -cb /etc/nginx/conf.d/auth-password user1
123456
[root@localhost ~] # systemctl restart nginx 重启
[root@localhost ~] # curl 192.168.168.155/real/
<html>
<head><title>401 Authorization Required</title></head>
<body>
<center><h1>401 Authorization Required</h1></center>
<hr><center>nginx/1.21.5</center>
</body>
</html>
[root@localhost ~] # curl 192.168.168.155/real/ -u user1
Enter host password for user 'user1' :
real-virtual
[root@localhost ~] # curl user1:123456@192.168.168.155/real
<html>
<head><title>301 Moved Permanently</title></head>
<body>
<center><h1>301 Moved Permanently</h1></center>
<hr><center>nginx/1.21.5</center>
</body>
</html>
[root@localhost ~] # curl user1:123456@192.168.168.155/real/
real-virtual
![](https://i-blog.csdnimg.cn/direct/e3af03023b534316bf6a455da95ec90b.png)
![](https://i-blog.csdnimg.cn/direct/593f72ba37e14624a63e254791b93599.png)
[root@localhost ~]# htpasswd -cb /etc/nginx/conf.d/auth-password user1 123456
Adding password for user user1
[root@localhost ~]# systemctl restart nginx.service
Adding password for user user1
[root@localhost ~]# systemctl restart nginx.service
![](https://i-blog.csdnimg.cn/direct/13dfbf7c4fa04d3199ae38981f12971e.png)
![](https://i-blog.csdnimg.cn/direct/1b1064f9490440869e4bad5dcdcadb2e.png)
![](https://i-blog.csdnimg.cn/direct/5e877b5c5079490b819008c6a3457e0b.png)