实验
4
:建立两个基于域名访问的网站,要求如下:
新建一个网站,域名为
www.ceshi.com
,设置网站首页目录为
/www/name
,网页内容为
this is
test
。
新建一个网站,域名为
rhce.first.day
,同时可通过
ce.first.day
访问,设置网站首页目录
为
/www/ce,
网页内容为:
today is first day of class
。
重启
实验
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
[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