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
相关推荐
一叶知秋yyds2 小时前
Centos 安装 Docker教程
linux·docker·centos
fie88892 小时前
在CentOS 7上集成cJSON库的方法
linux·运维·centos
带土12 小时前
5. Unix/Linux 系统常用类型别名清单
linux·unix
爱吃橘的橘猫2 小时前
如何解决VMware虚拟机中Linux系统终端不显示ens33 inet IP地址的问题
linux·运维·服务器·虚拟机
佐杰3 小时前
Jenkins使用指南1
java·运维·jenkins
kyle~3 小时前
计算机系统---USB的四种传输方式
运维·c++·计算机系统
无聊的小坏坏3 小时前
Select 服务器实战教学:从 Socket 封装到多客户端并发
服务器·select·io多路复用
一勺菠萝丶3 小时前
芋道后端部署后总自己挂?从 Nginx 报错到 OOM Kill 的完整排查与修复(2核2G 服务器实战)
服务器·chrome·nginx
梁正雄3 小时前
linux服务-Bonding网卡绑定工具
linux·运维·linux bonding·网卡绑定