Linux-第四章web服务

网站需求:

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两人可以访问,其他用户不能访问。

先配置环境

复制代码
systemctl stop firewalld
senforce 0
关闭防火墙
mount /div/sr0 /mnt
yum install nginx 
下载nginx


将域名www.openlab.com 解析成自己虚拟据的ip
Windows下的hosts文件路径:C:\Windows\System32\drivers\etc\hosts
Linux下的hosts文件路径:/etc/hosts
我的虚拟机ip是192.168.216.141
所以写 192.168.216.141 www.openlab.com

相关配置

复制代码
vim /etc/nginx/conf.d/dir.conf



server {
       listen 443 ssl http2;
       server_name www.openlab.com;   #要访问的域名
       root /openlab;
       charset utf-8,gbk;   #防止中文出现乱码
       ssl_certificate "/etc/pki/openlab.crt";   #  .crt   认证    .crs  证书请求文件
       ssl_certificate_key "/etc/pki/openlab.key";   # 私钥 
       location /student{
           alias /nginx/student;
           auth_basic "please login...";  #加密网页的验证信息
           auth_basic_user_file /etc/nginx/userfile;  #加密网页使用密码和用户
       }   #子网站路径
       location /data{
           alias /nginx/data;
       }   #子网站路径
       location /money{
           alias /nginx/money;
       }   #子网站路径
}
server{
       listen 80;
       server_name www.openlab.com;
       return 301 https://www.openlab.com;
}  #访问该网站http请求都通过https响应

mkdir /openlab  #创建文件夹
echo welcome to openlab! > /openlab/index.html  #写网站要显示的内容
mkdir /nginx/student -pv
echo 学生信息 > /nginx/student/index.html
mkdir /nginx/data -pv
echo 教学资料 > /nginx/data/index.html
mkdir /nginx/money -pv
echo 缴费网站 > /nginx/money/index.html
systemctl restart nginx

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

复制代码
dnf install httpd-tools -y  #下载软件
htpasswd -c /etc/nginx/userflie song  #用户song  密码就写123456
htpasswd -c /etc/nginx/userflie tian  #用户tian

创建私钥生成证书文件

复制代码
openssl  genrsa   2048 > /etc/pki/openlab.key
openssl req -utf8 -new  -key /etc/pki/openlab.key -x509  -days 365  -out
/etc/pki/openlab.crt

systemctl  restart nginx  #重启nginx
测试:https://www.openlab.com
相关推荐
chlk12312 小时前
Linux文件权限完全图解:读懂 ls -l 和 chmod 755 背后的秘密
linux·操作系统
舒一笑13 小时前
Ubuntu系统安装CodeX出现问题
linux·后端
改一下配置文件13 小时前
Ubuntu24.04安装NVIDIA驱动完整指南(含Secure Boot解决方案)
linux
碳基沙盒14 小时前
OpenClaw 多 Agent 配置实战指南
运维
深紫色的三北六号1 天前
Linux 服务器磁盘扩容与目录迁移:rsync + bind mount 实现服务无感迁移(无需修改配置)
linux·扩容·服务迁移
SudosuBash1 天前
[CS:APP 3e] 关于对 第 12 章 读/写者的一点思考和题解 (作业 12.19,12.20,12.21)
linux·并发·操作系统(os)
哈基咪怎么可能是AI2 天前
为什么我就想要「线性历史 + Signed Commits」GitHub 却把我当猴耍 🤬🎙️
linux·github
十日十行2 天前
Linux和window共享文件夹
linux
Sinclair2 天前
简单几步,安卓手机秒变服务器,安装 CMS 程序
android·服务器
木心月转码ing3 天前
WSL+Cpp开发环境配置
linux