web——搭建静态网站——基于http协议的静态网站

实验 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 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值