Linux网站搭建

一.网站需求:

1.基于域名www.openlab.com可以访问网站内容为 welcome to openlab!!!

复制代码
#关闭防火墙 SElinux
systemctl stop firewalld

setenforce 0
#安装服务
dnf install -y nginx

vim /etc/nginx/conf.d/test_name.conf
#添加
server{
        listen 192.168.190.131:80;
        root /www/openlab;
        server_name www.openlab.com;
        location / {

        }
}

#添加配置文件
vim /etc/hosts

192.168.190.131    www.openlab.com
#创建目录
mkdir -p /www/openlab
#写入内容
echo 'welcome openlab!!!' > /www/openlab/index.htm
#重启服务
systemctl restart nginx.service 

#验证服务
curl www.openlab.com

2.给该公司创建三个子界面分别显示学生信息,教学资料和缴费网站,基于www.openlab.com/student 网站访问学生信息,www.openlab.com/data网站访问教学资料

www.openlab.com/money网站访问缴费网站

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

server{
        listen 192.168.190.131:80;
        root /www/openlab;
        server_name www.openlab.com;
        location /student{
                alias /www/openlab/student/;
                auth_basic on;
                auth_basic_user_file /etc/nginx/users;
        }
        location /date{
                alias /www/openlab/date/;
        }
        location /money{
                alias /www/openlab/money/;
        }
}
#创建目录写入内容
[root@localhost ~]# mkdir /www/openlab/student
[root@localhost ~]# echo student > /www/openlab/student/index.html
[root@localhost ~]# mkdir /www/openlab/date
[root@localhost ~]# echo date > /www/openlab/date/index.html
[root@localhost ~]# mkdir /www/openlab/money
[root@localhost ~]# echo money > /www/openlab/money/index.html
#重启服务
systemctl restart nginx.service 

#验证
curl http://www.openlab.com/date/

3.要求

(1)访问该网站http请求都通过https响应。

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

复制代码
[root@localhost ~]# htpasswd -c /etc/nginx/users song
New password: 
Re-type new password: 
Adding password for user song
[root@localhost ~]# htpasswd /etc/nginx/users tian
New password: 
Re-type new password: 
Adding password for user tian

#添加配置文件
vim /etc/nginx/conf.d/test_httpd.conf

server{
        listen 192.168.190.131:443 ssl;
        root /www/openlab/money/;
        ssl_certificate /etc/pki/tls/certs/openlab.crt;
        ssl_certificate_key /etc/pki/tls/private/openlab.key;
        location /{
                index index.html;
        }
}

#证书
[root@localhost ~]# openssl req -utf8 -new -key /etc/pki/tls/private/openlab.key -x509 -days 365 -out /etc/pki/tls/certs/openlab.crt

You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:86
State or Province Name (full name) []:jiangsu
Locality Name (eg, city) [Default City]:nanjin
Organization Name (eg, company) [Default Company Ltd]:rhce
Organizational Unit Name (eg, section) []:server
Common Name (eg, your name or your server's hostname) []:server
Email Address []:andy@qq.com

#重启服务
systemctl restart nginx.service

#验证
curl https://www.openlab.com -k
相关推荐
码农小钻风9 分钟前
利用Samba实现局域网跨平台共享文件
linux·samba·共享
LN花开富贵29 分钟前
【ROS】鱼香ROS2学习笔记二
linux·笔记·python·学习·嵌入式
code tsunami1 小时前
如何在车辆数据自动化中解决Cloudflare Turnstile
运维·microsoft·自动化
GS8FG1 小时前
Busybox生成根文件系统,并移植e2fsprogs:RK3568
linux·驱动开发
翼龙云_cloud2 小时前
亚马逊云代理商:CloudWatch Agent 全解析 5 步实现服务器监控
运维·服务器·云计算·aws·云服务器
Cyber4K3 小时前
【Nginx专项】基础入门篇:状态页、微更新、内容替换、读取、压缩及防盗链
linux·运维·服务器·nginx·github
shining4 小时前
当拿到一个新服务器时所需准备工作
linux·程序员
门思科技4 小时前
LoRaWAN项目无需NS和平台?一体化网关如何简化部署与成本
服务器·网络·物联网
Bruce_Liuxiaowei4 小时前
顺藤摸瓜:一次从防火墙告警到设备实物的溯源实战
运维·网络·网络协议·安全
maosheng11464 小时前
linux的综合教程(搭建论坛教程)
linux