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
相关推荐
sulikey1 小时前
Linux ext2文件系统结构
linux·操作系统·文件系统·linux文件系统·ext2·ext2文件系统
白菜欣2 小时前
Linux — 进程控制
android·linux·运维
JoneBB2 小时前
ABAP Webservice连接
运维·开发语言·数据库·学习
皮卡狮2 小时前
Linux开发专属工具
linux
weixin_421725262 小时前
Linux 编程语言全解析:C、C++、Python、Go、Rust 谁更强?
linux·python·go·c·编程语言
Tolalal3 小时前
Vmware Ubuntu虚拟机扩容
linux·运维·ubuntu
咚为3 小时前
比AccessLog更全面的原生Nginx 日志记录
运维·nginx·junit
我星期八休息3 小时前
Linux系统编程—基础IO
linux·运维·服务器·c语言·c++·人工智能·算法
Shingmc33 小时前
【Linux】数据链路层
linux·服务器·网络
a752066284 小时前
零基础实操:小龙虾 AI OpenClaw 接入 Kimi 详细步骤
运维·服务器