学习linux必学的内部web网站搭建——三分钟OK!

发布于:2023-01-03 ⋅ 阅读:(246) ⋅ 点赞:(0)

请给openlab搭建web网站
网站需求:

1.基于域名[www.openlab.com](http://www.openlab.com)可以访问网站内容为 welcome to openlab!!!

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

[www.openlab.com/money网站访问缴费网站](http://www.openlab.com/money网站访问缴费网站)。

3.要求

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

​ (2)访问缴费网站实现数据加密基于https访问。

1.挂载

[root@Client ~]# mount /dev/sr0  /mnt

#显示已经挂载
mount: /mnt: /dev/sr0 already mounted on /mnt.

2.配置yum源

#先切换目录

[root@Client ~]# cd /etc/yum.repos.d/

#打开base.reo 开始配置本地yum源

[root@Client yum.repos.d]# vim base.repo 

2.1 本地yum源

[BaseOS]
name=BaseOS
baseurl=file:///mnt/BaseOS/
gpgcheck=0
enabled=1
[AppStream]
name=AppStream
baseurl=file:///mnt/AppStream/
gpgcheck=0

3.查看是否存在httpd

[root@Client ~]# rpm -qa | grep httpd
httpd-filesystem-2.4.37-41.module+el8.5.0+11772+c8e0c271.noarch
httpd-2.4.37-41.module+el8.5.0+11772+c8e0c271.x86_64
redhat-logos-httpd-84.5-1.el8.noarch
httpd-tools-2.4.37-41.module+el8.5.0+11772+c8e0c271.x86_64

3.1 不存在就下载

[root@Client ~]# yum install httpd  -y

4.关闭防火墙和selinux

[root@Client ~]# systemctl stop firewalld
[root@Client ~]# setenforce 0  

5.配置httpd 

[root@Client ~]# vim /etc/httpd/conf.d/vhosts.conf 

<VirtualHost 192.168.58.100:80>
        DocumentRoot /openlab
        ServerName www.openlab.com
</VirtualHost>
<Directory /openlab>
        AllowOverride none
        Require all granted
</Directory>
<Directory /openlab/student>
        AuthType basic
        AuthName "登陆"

#第一个目录允许所有

#第二个目录模块通过用户控制实现(用户名和密码访问openlab网站)
        AuthUserfile /etc/httpd/users
        Require user song tian
</Directory>

5.1 配置详情

6.根据子配置文件添加用户

[root@Client ~]# htpasswd -c /etc/httpd/users song
New password: 
Re-type new password: 
Adding password for user song
[root@Client ~]# htpasswd  /etc/httpd/users tian
New password: 
Re-type new password: 
Adding password for user tian

7.根据子配置文件创建目录

[root@Client ~]# mkdir /openlab/{student,data,moeny} -pv
mkdir: 已创建目录 '/openlab'
mkdir: 已创建目录 '/openlab/student'
mkdir: 已创建目录 '/openlab/data'
mkdir: 已创建目录 '/openlab/moeny'

8.编辑配置文件编写域名和ip对应关系

[root@Client ~]# vim /etc/hosts 

 9.编写网站资源信息(文件名写错修改)

[root@Client ~]# echo welcome to openlab > /openlab/index.html
[root@Client ~]# echo student > /openlab/student/index.html

[root@Client ~]# echo data> /openlab/data/index.html
[root@Client ~]# mv /openlab/moeny   /openlab/money

[root@Client ~]# ll /openlab/
总用量 16
drwxr-xr-x. 2 root root 4096 8月  31 17:39 data
-rw-r--r--. 1 root root   19 8月  31 17:44 index.html
drwxr-xr-x. 2 root root 4096 8月  31 17:39 money
drwxr-xr-x. 2 root root 4096 8月  31 17:44 student
[root@Client ~]# echo money > /openlab/money/index.html

 10.测试配置文件是否可执行并重启httpd

[root@Client ~]# httpd -t
Syntax OK
[root@Client ~]# systemctl restart httpd
 

11. 登陆

 11.1 song登陆student

 

  11.2 tian登陆student

 

 11.3 其他用户登陆student

12.使用域名测试

 

 12.1 student使用域名测试

 12.2 使用song 登陆student

 12.3 使用tian 登陆student

12.4 测试data

12.5 测试money

本文含有隐藏内容,请 开通VIP 后查看