Bootstrap

配置Wab服务器,访问网站,并显示内容—— 练习二

题目二

1.新建一个网站,该网站网址为www.world.com,用户访问该网站时网站显示:  欢迎来到这个世界!Welcome;

2.当用户访问www.world.com/study/网站时,网站内容显示为:good good study,day day up

3.当用户访问www.world.com/computer/网站时,必须要使用账号名root,密码为777才能访问,该网站内容为:KNOW

[root@localhost ~]# dnf install nginx -y

#添加ip地址
[root@localhost ~]# nmtui
[root@localhost ~]# nmcli connection up ens224

#创建网页文件根目录,并定义网页内容
[root@localhost ~]# vim /www/world/index.html
[root@localhost ~]# cat /www/world/index.html

<head>	
	<meta charset="utf-8">
</head>

欢迎来到这个世界!Welcome

[root@localhost ~]# mkdir -pv /www/world


#配置文件
[root@localhost ~]# vim /etc/nginx/conf.d/test_world.conf
[root@localhost ~]# cat /etc/nginx/conf.d/test_world.conf

server {
	listen 192.168.50.102:80;
	server_name www.world.com;
	root /www/world;
	location /study/{}
	location /computer {
		auth_basic on;
		auth_basic_user_file /etc/nginx/conf.d/auth-password;
	}
}

[root@localhost ~]# vim /www/world/study/index.html
[root@localhost ~]# cat /www/world/study/index.html
good good study,day day up
[root@localhost ~]# vim /www/world/computer/index.html
[root@localhost ~]# cat /www/world/computer/index.html
KNOW
[root@localhost ~]# tree /www/world/
/www/world/
├── computer
│   └── index.html
├── index.html
└── study
    └── index.html

2 directories, 3 files

[root@localhost ~]# mkdir -pv /www/world/{study,computer}
mkdir: 已创建目录 '/www/world/study'
mkdir: 已创建目录 '/www/world/computer'

[root@localhost ~]# vim /etc/hosts
[root@localhost ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.50.102 www.world.com

[root@localhost ~]# dnf install httpd-tools -y

[root@localhost ~]# htpasswd -cb /etc/nginx/conf.d/auth-password root 777
Adding password for user root

#关闭防火墙
[root@localhost ~]# systemctl disable firewalld --now

#设置selinux,必须设置,否则无法看到网页页面内容
[root@localhost ~]# setenforce 0
[root@localhost ~]# getenforce
Permissive
[root@localhost ~]# systemctl restart nginx


#以下为鉴定部分
[root@localhost ~]# curl 192.168.50.102

<head>	
	<meta charset="utf-8">
</head>

欢迎来到这个世界!Welcome
[root@localhost ~]# curl 192.168.50.102/study/
good good study,day day up

[root@localhost ~]# curl 192.168.50.102/computer/
<html>
<head><title>401 Authorization Required</title></head>
<body>
<center><h1>401 Authorization Required</h1></center>
<hr><center>nginx/1.20.1</center>
</body>
</html>

#需要使用账户和密码登录
[root@localhost ~]# curl root:[email protected]/computer/
KNOW


[root@localhost ~]# curl www.world.com
<head>	
	<meta charset="utf-8">
</head>

欢迎来到这个世界!Welcome

[root@localhost ~]# curl www.world.com/study/
good good study,day day up

[root@localhost ~]# curl root:[email protected]/computer/
KNOW

;