《Linux 环境下 Nginx 多站点综合实践:域名解析、访问控制与 HTTPS 加密部署》

综合练习:请给openlab搭建web网站,网站需求:

1.基于域名www.openlab.com可以访问网站内容为 welcome to openlab!!,

2.给该公司创建三个子界面分别显示学生信息,教学资料和缴费网站,基于www.openlab.com/student 网站访问学生信息,www.openlab.com/data网站访问教学资料www.openlab.com/money 网站访问缴费网站

3.要求

(1)学生信息网站只有song和tian两人可以访问,其他用户不能访问。

(2)访问缴费网站实现数据加密基于https访问。

一、(1)首先关闭安全软件firewalld和selinux,并下载nginx 和 mod_ssl

shell 复制代码
[root@master ~]# systemctl status firewalld
○ firewalld.service - firewalld - dynamic firewall daemon
     Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
     Active: inactive (dead)
       Docs: man:firewalld(1)
[root@master ~]# getenforce
Disabled
[root@master ~]# yum install nginx mod_ssl -y
#开启软件并设置开机自启动
[root@master ~]# systemctl enable --now nginx
Created symlink /etc/systemd/system/multi-user.target.wants/nginx.service → /usr/lib/systemd/system/nginx.service.

(2)准备工作做完之后,创建www.openlab.com网站

shell 复制代码
[root@master ~]# mkdir /www/openlab -p
[root@master ~]# echo "Welcome to xi'an" > /www/openlab/index.html

修改配置文件并重启

shell 复制代码
[root@master ~]# vim /etc/nginx/nginx.conf
[root@master ~]# systemctl restart nginx

并在wendows系统中C:\Windows\System32\drivers\etc的hosts文件中进行DNS映射,红框选中IP为本机IP

(3)在windows端打开浏览器进行测试

二、创建教学资料www.openlab.com/money子网站

shell 复制代码
[root@master ~]# mkdir /www/openlab/data
[root@master ~]# echo "data" > /www/openlab/data/index.html

在系统文件中之前的编辑下继续编辑(红框中为添加配置)

shell 复制代码
[root@master ~]# vim /etc/nginx/nginx.conf
[root@master ~]# systemctl restart nginx

然后在Windows端打开浏览器输入www.openlab.com/data测试

三、创建学生信息www.openlab.com/student 子网站

shell 复制代码
[root@master ~]# mkdir /www/openlab/student
[root@master ~]# echo "student" > /www/openlab/student/index.html
[root@master ~]# useradd song
[root@master ~]# echo "123456" | passwd --stdin song
更改用户 song 的密码 。
passwd:所有的身份验证令牌已经成功更新。
[root@master ~]# useradd tian
[root@master ~]# echo "123456" | passwd --stdin tian
更改用户 tian 的密码 。
passwd:所有的身份验证令牌已经成功更新。
#设置登录网页的密码
[root@master ~]# htpasswd -c /www/openlab/student/passwd song
[root@master ~]# htpasswd  /www/openlab/student/passwd tian #第二次不能有-c这个参数,否则会重置之前保存的密码

继续编写我们的系统文件

shell 复制代码
[root@master ~]# vim /etc/nginx/nginx.conf
[root@master ~]# systemctl restart nginx

Windows端打开浏览器输入www.openlab.com/student测试,多次测试需要清除浏览器缓存

然后输入我们要登录的用户song

用户tian

四、创建缴费www.openlab.com/money子网站。

shell 复制代码
[root@master ~]# mkdir /www/openlab/money
[root@master ~]# echo "money" > /www/openlab/money/index.html

制作私钥密码

制作证书

去掉私钥密码

修改配置文件

shell 复制代码
[root@master ~]# vim /etc/nginx/nginx.conf
[root@master ~]# systemctl restart nginx

Windows端打开浏览器输入https://www.openlab.com/money测试

此时点击高级 选择继续访问


综上所述所有网站搭建完毕。

相关推荐
m0_6948455740 分钟前
服务器系统时间不准确怎么办?
linux·运维·服务器·游戏·云计算
JIONG44 分钟前
设置当前目录文件名为小写
linux
星哥说事1 小时前
Rocky Linux 9 快速安装 Node.js
linux
一分半心动1 小时前
宝塔访问lnmp项目,跳转不到项目根目录问题解决
linux
过往入尘土1 小时前
linux中的各种dmo语句(一些)
linux·运维·服务器
海文宇2 小时前
Linux的目录
linux·运维·服务器
用户呢称3 小时前
Linux | LVS--Linux虚拟服务器知识点(下)
linux·服务器·lvs
zoulingzhi_yjs3 小时前
Linux LVS集群技术
linux·服务器·lvs
cqh2053 小时前
LVS(Linux Virtual Server) 集群
linux·运维·lvs
Aa hui3 小时前
LVS 集群技术基础
linux·centos·lvs