网站需求:
1.基于域名[www.openlab.com](http ://www.openlab.com)可以访问网站内容为 welcome to openlab!!!
2.给该公司创建三个子界面分别显示学生信息,教学资料和缴费网站,基于[www.openlab.com/student](http://www.openlab.com/student) 网站访问学生信息,[www.openlab.com/data](http://www.openlab.com/data)网站访问教学资料,网站访问缴费网站(http://www.openlab.com/money网站访问缴费网站)。
3.要求
(1)学生信息网站只有song和tian两人可以访问,其他用户不能访问。
(2)访问缴费网站实现数据加密基于https访问。
操作过程
1.关闭防火墙, SELinux
[root@server ~]# setenforce 0
[root@server ~]# systemctl stop firewalld
[root@server ~]# systemctl disable firewalld
检查:
[root@localhost ~]# getenforce
Permissive
[root@localhost ~]# 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)
2.安装nginx + httpd-tools
dnf install nginx httpd-tools -y
3.创建网站目录、网页文件
mkdir -p /usr/share/nginx/html/{student,data,money}
echo "welcome to openlab!!!" > /usr/share/nginx/html/index.html
echo "学生信息页面" > /usr/share/nginx/html/student/index.html
echo "教学资料页面" > /usr/share/nginx/html/data/index.html
echo "缴费网站页面" > /usr/share/nginx/html/money/index.html
4.生成自签名 SSL 证书(给 money 的 HTTPS 加密)
[root@localhost html]# openssl req -newkey rsa:2048 -nodes -sha256 -keyout /etc/pki/tls/private/openlab.key -x509 -days 365 -out /etc/pki/tls/certs/openlab.crt -subj "/CN=www.openlab.com"
5.创建基础认证密码文件,添加 song、tian 用户
# -c 创建新文件,添加第一个用户song
htpasswd -c /etc/nginx/userfile song
# 追加tian用户,不要-c参数
htpasswd /etc/nginx/userfile tian
# 查看密码文件 cat /etc/nginx/userfile
6.修改 nginx 配置文件
[root@localhost ~]# vim /etc/nginx/nginx.conf

7.配置域名解析
vim /etc/hosts
192.168.152.129 www.openlab.com
8.检查配置文件,启动服务
nginx -t
systemctl enable nginx --now
systemctl restart nginx
9.windows测试
(客户端)本地主机 window 路径 hosts: C:\Windows\System32\drivers\etc\hosts 文件中编辑内容 ---注意权限,用管理员身份记事本打开,末尾添加: 192.168.152.129 www.openlab.com
cmd ping一下www.openlab.com观察返回的ip是不是刚刚添加的虚拟机ip
浏览器搜索https://www.openlab.com

本文介绍基于Nginx部署多路径Web站点(/student、/data、/money)的完整流程,包括域名配置、目录结构创建、基础认证(htpasswd限制/student访问)、自签名SSL证书生成以实现/money路径HTTPS加密,以及SELinux与防火墙关闭等前置环境配置。重点涵盖Web服务安全访问控制与HTTPS实践。
469

被折叠的 条评论
为什么被折叠?



