RHCE-网站搭建
一.需求
网站需求:
1.基于域名www.openlab.com可以访问网站内容为 welcome to openlab!!!
2.给该公司创建三个子界面分别显示学生信息,教学资料和缴费网站,基于www.openlab.com/student 网站访问学生信息,www.openlab.com/data网站访问教学资料
www.openlab.com/money网站访问缴费网站。
3.要求 (1)访问该网站http请求都通过https响应。
(2)学生信息网站只有song和tian两人可以访问,其他用户不能访问。
二.配置过程
(1)准备工作
[root@localhost /]# systemctl disable firewalld #关闭防火墙[root@localhost /]# systemctl disable selinux #关闭selinux[root@localhost /]# yum install nginx -y #安装nginx(2) 配置
1.基于域名www.openlab.com可以访问网站内容为 welcome to openlab!!!
[root@localhost /]# mkdir /usr/share/nginx/html/openlab
[root@localhost /]#echo "welcome to openlab" > /usr/share/nginx/html/openlab/index.html
2.给该公司创建三个子界面分别显示学生信息,教学资料和缴费网站,基于www.openlab.com/student 网站访问学生信息,www.openlab.com/data网站访问教学资料
www.openlab.com/money网站访问缴费网站。
[root@localhost /]# mkdir /usr/share/nginx/html/openlab/{student,data,money} -p
[root@localhost /]# echo "学生信息页面" > /usr/share/nginx/html/openlab/student/index.html
[root@localhost /]# echo "教育资料" > /usr/share/nginx/html/openlab/data/index.html
[root@localhost /]# echo "缴费信息" > /usr/share/nginx/html/openlab/money/index.html
3.要求 (1)访问该网站http请求都通过https响应。
(2)学生信息网站只有song和tian两人可以访问,其他用户不能访问。
[root@localhost /]# vim /etc/nginx/conf.d/ssl.conf #进行ssl配置
server {listen 80 default_server; # 监听 HTTP 的 80 端口server_name www.openlab.com; # 定义服务器名称为 www.openlab.comreturn 301 https://www.openlab.com/; # 返回301重定向,将所有 HTTP 请求重定向到 HTTPS
}server {listen 443 ssl http2; # 监听 HTTPS 的 443 端口listen [::]:443 ssl http2;server_name www.openlab.com; # 再次定义服务器名称为 www.openlab.comroot /usr/share/nginx/html/openlab; # 设置网站的根目录为 /usr/share/nginx/html/openlabssl_certificate "/etc/pki/nginx/openlab.crt"; # 指定 SSL 证书的路径ssl_certificate_key "/etc/pki/nginx/openlab.key"; # 指定与 SSL 证书对应的私钥路径ssl_session_cache shared:SSL:1m; # 设置 SSL 会话缓存,名称为 SSL,大小为 1MBssl_session_timeout 10m; # 设置 SSL 会话超时时间为 10 分钟ssl_ciphers PROFILE=SYSTEM;ssl_prefer_server_ciphers on;
}
[root@localhost /]# mkdir /etc/pki/nginx
[root@localhost /]# openssl genrsa 2048 > /etc/pki/nginx/openlab.key
[root@localhost /]# openssl req -utf8 -new -key /etc/pki/nginx/openlab.key -x509 -days 365 -out /etc/pki/nginx/openlab.crt
[root@localhost /]# mkdir /etc/nginx/passwd
[root@localhost /]# htpasswd -bc /etc/nginx/passwd song 123 #创建用户song密码123
[root@localhost /]# htpasswd -b /etc/nginx/passwd tian 123 #创建用户tian密码123三.结果验证
[root@localhost /]# curl -I http://www.openlab.com
HTTP/1.1 301 Moved Permanently
Server: nginx/1.20.1
Date: Sat, 08 Nov 2025 12:00:50 GMT
Content-Type: text/html
Content-Length: 169
Connection: keep-alive
Location: https://www.openlab.com/ #表明HTTP已重定向到HTTPS[root@localhost /]# curl -k https://www.openlab.com
welcome to openlab
[root@localhost /]# curl -k https://www.openlab.com/data/
教育资料
[root@localhost /]# curl -k https://www.openlab.com/money/
缴费信息
[root@localhost /]# curl -k https://www.openlab.com/student/
学生信息页面
[root@localhost /]# curl -k https://song:123@www.openlab.com/student/
学生信息页面
[root@localhost /]# curl -k https://tian:123@www.openlab.com/student/
学生信息页面
