《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测试

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


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

相关推荐
宴之敖者、12 分钟前
Linux——git和gdb
linux·运维·git
TangDuoduo000522 分钟前
【Linux字符设备驱动】
linux·驱动开发
代码游侠23 分钟前
学习笔记——Linux内核与嵌入式开发2
linux·运维·arm开发·嵌入式硬件·学习·架构
Fᴏʀ ʏ꯭ᴏ꯭ᴜ꯭.26 分钟前
Nginx性能调优与压测实战指南
运维·nginx
郝学胜-神的一滴27 分钟前
深入Linux网络编程:accept函数——连接请求的“摆渡人”
linux·服务器·开发语言·网络·c++·程序人生
小义_37 分钟前
【Docker】知识一
linux·docker·云原生·容器
wefg142 分钟前
【Linux】进程地址空间深入理解
linux·运维·服务器
ZHANG13HAO44 分钟前
android13 4G网络环境和wifi内网说明
linux·服务器·网络
Linux运维技术栈1 小时前
Magento 2.3.5 宝塔Linux环境完整安装指南(避坑版+图文详解)
linux·运维·服务器
古月-一个C++方向的小白1 小时前
Linux——命令行参数与环境变量
linux·运维