当前位置: 首页 > news >正文

在 Linux 环境下搭建 OpenLab Web 网站并实现 HTTPS 和访问控制

实验要求

综合练习:请给openlab搭建web网站
​ 网站需求:
​ 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)网站访问教学资料
​ [www.openlab.com/money网站访问缴费网站](http://www.openlab.com/money网站访问缴费网站)。
​ 3.要求
​ (1)学生信息网站只有song和tian两人可以访问,其他用户不能访问。
​ (2)访问缴费网站实现数据加密基于https访问。

注意点

在 Nginx 中,默认的 Web 根目录是 /usr/share/nginx/html

  • /usr/share/nginx/html/index.html:欢迎页面。
  • /usr/share/nginx/html/student.html:学生信息页面。
  • /usr/share/nginx/html/data.html:教学资料页面。
  • /usr/share/nginx/html/money.html:缴费页面。

实验过程

[root@node ~]# yum install nginx -y
[root@node ~]# systemctl start nginx
[root@node ~]# systemctl enable nginx
[root@node ~]# cd /etc/nginx/
[root@node nginx]# tree
.
├── conf.d
├── default.d
├── fastcgi.conf
├── fastcgi.conf.default
├── fastcgi_params
├── fastcgi_params.default
├── koi-utf
├── koi-win
├── mime.types
├── mime.types.default
├── nginx.conf
├── nginx.conf.default
├── scgi_params
├── scgi_params.default
├── uwsgi_params
├── uwsgi_params.default
└── win-utf2 directories, 15 files
[root@node nginx]# cd /usr/share/nginx/html
[root@node html]# vim index.html 
<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Welcome to OpenLab!</title>
</head>
<body><h1>Welcome to OpenLab!!!</h1>
</body>
</html>[root@node html]# vim data.html
<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Teaching Materials</title>
</head>
<body><h1>Teaching Materials</h1><p>Resources and notes for the course.</p>
</body>
</html>[root@node html]# vim money.html
<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Payment Portal</title>
</head>
<body><h1>Payment Portal</h1><p>Please make your payment here.</p>
</body>
</html>[root@node html]# yum install httpd-tools -y[root@node html]# htpasswd -c /etc/nginx/.htpasswd song
New password: 
Re-type new password: 
Adding password for user song
[root@node html]# htpasswd /etc/nginx/.htpasswd tian
New password: 
Re-type new password: 
Adding password for user tian[root@node ~]# vim /etc/nginx/nginx.conf
pid /var/run/nginx.pid;events {worker_connections 1024;
}http {include       /etc/nginx/mime.types;default_type  application/octet-stream;access_log  /var/log/nginx/access.log;error_log   /var/log/nginx/error.log;server {listen       80;server_name  www.openlab.com;location / {root   /usr/share/nginx/html;index  index.html index.htm;}# 学生信息页面(要求 Basic Auth)location /student {auth_basic "Restricted Access";  # 显示的提示信息auth_basic_user_file /etc/nginx/.htpasswd;  # 指向用户密码文件# 其他配置}# 教学资料页面(对所有用户开放)location /data {root   /usr/share/nginx/html/data;index  index.html index.htm;}# 缴费页面(强制使用 HTTPS)location /money {root   /usr/share/nginx/html/money;index  index.html index.htm;return 301 https://$server_name$request_uri;}}# SSL 配置(可选)server {listen       443 ssl;server_name  www.openlab.com;ssl_certificate      /etc/ssl/certs/openlab.crt;ssl_certificate_key  /etc/ssl/private/openlab.key;location / {root   /usr/share/nginx/html;index  index.html index.htm;}# 学生信息页面(要求 Basic Auth)location /student {auth_basic "Restricted Access";auth_basic_user_file /etc/nginx/.htpasswd;}location /data {root   /usr/share/nginx/html/data;index  index.html index.htm;}location /money {root   /usr/share/nginx/html/money;index  index.html index.htm;}}
}[root@node ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful[root@node ~]# systemctl restart nginx[root@node ~]# vim  /usr/share/nginx/html/index.html[root@node ~]# vim /etc/hosts[root@node ~]# ping www.openlab.com
PING www.openlab.com (192.168.133.20) 56(84) 字节的数据。
64 字节,来自 www.openlab.com (192.168.133.20): icmp_seq=1 ttl=64 时间=0.028 毫秒
64 字节,来自 www.openlab.com (192.168.133.20): icmp_seq=2 ttl=64 时间=0.031 毫秒
64 字节,来自 www.openlab.com (192.168.133.20): icmp_seq=3 ttl=64 时间=0.028 毫秒

主界面 

student

 

 

http://www.lryc.cn/news/497258.html

相关文章:

  • 微信小程序wx.showShareMenu配置全局分享功能
  • 机器学习面试八股总结
  • 南京邮电大学《2024年812自动控制原理真题》 (完整版)
  • 大数据新视界 -- Hive 数据湖集成与数据治理(下)(26 / 30)
  • Android EventBus最全面试题及参考答案
  • C++ 游戏开发:开启游戏世界的编程之旅(1)
  • SpringBoot mq快速上手
  • 图像处理网络中的模型水印
  • Halcon 瑕疵检测原理及应用
  • JAVA 架构师面试 100套含答案:JVM+spring+ 分布式 + 并发编程》...
  • 多模态学习详解
  • C#应用开发:基于C# WPF界面实现本机网络通讯状态(下载速度)的显示
  • Octo—— 基于80万个机器人轨迹的预训练数据集用于训练通用机器人,可在零次拍摄中解决各种任务
  • 2022高等代数下【南昌大学】
  • UDP编程
  • 论文阅读:Omnidirectional Image Super-resolution via Bi-projection Fusion
  • Web 毕设篇-适合小白、初级入门练手的 Spring Boot Web 毕业设计项目:智行无忧停车场管理系统(前后端源码 + 数据库 sql 脚本)
  • 微服务的负载均衡可以通过哪些组件实现
  • Spring Boot 支持哪些云环境?
  • 第31天:安全开发-JS应用WebPack打包器第三方库JQuery安装使用安全检测
  • word如何快速创建目录?
  • 关于linux 下的中断
  • 两个畸变矩阵相乘后还是一个2*2的矩阵,有四个畸变元素。1、畸变矩阵吸收了法拉第矩阵。2、畸变矩阵也给法拉第旋转角带来模糊(求解有多种可能)
  • MCU利用单总线协议(1-wire)读取DHT11温湿度
  • [保姆式教程]使用目标检测模型YOLO11 OBB进行旋转目标检测:训练自己的数据集(基于卫星和无人机的农业大棚数据集)
  • 【网络安全】网站常见安全漏洞 - 网站基本组成及漏洞定义
  • Redis——个人笔记留存
  • 人工智能_大模型091_大模型工作流001_使用工作流的原因_处理复杂问题_多轮自我反思优化ReAct_COT思维链---人工智能工作笔记0236
  • linux上jdk1.8安装elasticsearch6.8.5踩坑总结
  • Three.js教程_02场景、相机与渲染器全面解析