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
相关推荐
努力努力再努力wz18 分钟前
【Docker 入门系列】:从 Namespace、CGroup 到 LXC:理解容器运行时、rootfs 与 LXC 实战
运维·docker·容器
ao-weilai39 分钟前
Linux网络编程:网络知识基础
linux·网络·php
GeW1 小时前
RHCE10一次过!提高通过率+快速拿证的7个核心技巧
linux
JavaPub-rodert1 小时前
Docker 多阶段构建:为什么生产环境镜像可以小 90%
运维·docker·容器
浅念-1 小时前
C++ Protobuf 入门实战:基于通讯录项目吃透proto3语法与序列化
linux·服务器·网络·c++·protobuf·proto·proto3
qq_349447951 小时前
阿里云centos7.9系统安装jenkins
服务器·阿里云·jenkins
不怕犯错,就怕不做2 小时前
RK linux在buildroot中如何添加linux命令
linux·驱动开发·嵌入式硬件
2601_962218472 小时前
万象生鲜系统多账套隔离技术适配集团生鲜企业集团化数字化管控
大数据·运维·微服务·云原生·架构
M158227690552 小时前
ModbusTCP 转 Profinet 网关:上位机控制 PN 伺服方案
服务器·网络·tcp/ip
小羊在睡觉2 小时前
HLS视频
linux·后端·golang