实验要求:用户授权访问和搭建基于域名的虚拟主机,基于
ip
地址,基于端口的虚拟主机
实验步骤:
1.
基于
ip
地址
首先挂载,然后我查看下我有没有
httpd
,如果没有就有
rpm
安装
httpd
650) this.width=650;" title="01.png" src="/upload/getfiles/default/2022/11/15/20221115091058541.jpg" />
650) this.width=650;" title="1.png" src="/upload/getfiles/default/2022/11/15/20221115091059149.jpg" />
然后用
vi
编辑器进入
httpd.conf
配置文件,改下监听端口(是你
linuX
自己的
ip
地址),
在改一个完全合格域名
650) this.width=650;" title="2.png" src="/upload/getfiles/default/2022/11/15/20221115091059556.jpg" />
650) this.width=650;" title="3.png" src="/upload/getfiles/default/2022/11/15/20221115091100466.jpg" />
启动服务,并且关闭防火墙
650) this.width=650;" title="4.png" src="/upload/getfiles/default/2022/11/15/20221115091100888.jpg" />
在宿主机上打开网页输入
ip
地址
192.168.10.10
,打开了
apache
默认网页
650) this.width=650;" title="5.png" src="/upload/getfiles/default/2022/11/15/20221115091101404.jpg" width="1200" height="554" />
你可以
echo
一个,把默认网页改成
this is apache toot
650) this.width=650;" title="6.png" src="/upload/getfiles/default/2022/11/15/20221115091102474.jpg" />
在回到宿主机上看一下
650) this.width=650;" title="7.png" src="/upload/getfiles/default/2022/11/15/20221115091102756.jpg" />
我是想看他支不支持
index.txt
格式,我把
index.html
的文件导入到我新建的index.txt
650) this.width=650;" title="8.png" src="/upload/getfiles/default/2022/11/15/20221115091103455.jpg" width="586" height="43" />
回到宿主机上输入ip地址,结果是默认
650) this.width=650;" title="9.png" src="/upload/getfiles/default/2022/11/15/20221115091103809.jpg" width="645" height="300" />
如果想然他支持
index.txt
格式,就要进入
vi
编辑器
httpd.conf
配置文件中找到
DirectoryIndex,
在这里加个
index.txt
格式,并且
wq
保存并退出
650) this.width=650;" title="10.png" src="/upload/getfiles/default/2022/11/15/20221115091104318.jpg" width="668" height="426" />
在回到宿主机上,输入ip地址
650) this.width=650;" title="11.png" src="/upload/getfiles/default/2022/11/15/20221115091104816.jpg" width="722" height="299" />
创建虚拟目录
用vi编辑器配置虚拟目录:
#
是注释掉
Alias /test "/opt/test/"
(定义个名字也就是虚拟目录)(物理路径)
<Directory "/opt/test/">
(开头定义物理路径)
Options Indexes MultiViews FollowSymLinks
(建立索引,固定格式)
AllowOverride None
(不让他重写)
AuthName "hello"
(标志性信息)
authtype basic
(认证类型:基本认证)
authuserfile /etc/httpd/user
(身份验证登陆,要有个账户文件)
# authgroupfile /etc/httpd/group
(创建认证组)
# require Valid-user
(开启用户认证)
# require user test
(尽允许哪些用户)
# Require group admin
(尽允许哪些组)
</Directory>
650) this.width=650;" title="12.png" src="/upload/getfiles/default/2022/11/15/20221115091105274.jpg" />
查看所有创建
conf conf.d
,
Include conf.d/*.conf
这句话的意思是支持你自己创建的
conf.d/ *conf(*
代表所有
)
的配置文件
650) this.width=650;" title="13.png" src="/upload/getfiles/default/2022/11/15/20221115091105648.jpg" />
在
opt
下面创建
toot
,并且
echo
一个定义
this is vdir toot
650) this.width=650;" title="14.jpg" src="/upload/getfiles/default/2022/11/15/20221115091106096.jpg" />
开启服务
650) this.width=650;" title="15.png" src="/upload/getfiles/default/2022/11/15/20221115091106464.jpg" />
在宿主机上输入
ip
,
650) this.width=650;" title="16.png" src="/upload/getfiles/default/2022/11/15/20221115091106826.jpg" />
2.
用户授权限制
打开
vi
编辑器
vdir.conf
配置文件把
#
去掉
require Valid-user
(开启用户认证)
650) this.width=650;" title="1.png" src="/upload/getfiles/default/2022/11/15/20221115091107237.jpg" />
查看
httpd
下面有没有
,
然后在
/etc/httpd/user
创建用户
Tom
,并设置密码,创建好之后查看有没有用户,并且开启服务
650) this.width=650;" title="2.png" src="/upload/getfiles/default/2022/11/15/20221115091107721.jpg" />
在到宿主机上登录
650) this.width=650;" title="3.png" src="/upload/getfiles/default/2022/11/15/20221115091108103.jpg" />
3.
基于域名的虚拟主机
(
相同端口相同
ip,
不同主机名
)
进入
vi
编辑器创建
host.conf
配置文件
NameVirtualHost 192.168.100.101:80
(指定
ip
地址以及相对应的端口)
<VirtualHost 192.168.100.101:80>
(
ip
地址端口的固定模式)
ServerAdmin webmaster@dummy-host.example.com
(管理员邮箱)
DocumentRoot /opt/benet/
(定义站点目录)
ServerName www.benet.com
(服务器名字)
ErrorLog logs/benet.com-error_log
(错误日志)
CustomLog logs/benet.com-access_log common
(访问日志)
</VirtualHost>
在这里要做两个不同网站,一个是
benet
另一个是
accp,
650) this.width=650;" title="1.png" src="/upload/getfiles/default/2022/11/15/20221115091108784.jpg" />
创建两个站点,在往两个站点写点东西
650) this.width=650;" title="2.png" src="/upload/getfiles/default/2022/11/15/20221115091109267.jpg" />
基于主机名肯定要做
DNS
进行解析,下面安装
dns
650) this.width=650;" title="3.png" src="/upload/getfiles/default/2022/11/15/20221115091109695.jpg" />
安装好之后,在主配置文件中改监听端口
650) this.width=650;" title="4.png" src="/upload/getfiles/default/2022/11/15/20221115091110070.jpg" />
在进入区域配置文件中配置,创建两个区域
benet
、
accp
650) this.width=650;" title="5.png" src="/upload/getfiles/default/2022/11/15/20221115091110847.jpg" />
在到工作目录下
650) this.width=650;" title="06.png" src="/upload/getfiles/default/2022/11/15/20221115091111321.jpg" />
查看下权限,然后把
named.localhost
复制到
benet.com.zone
650) this.width=650;" title="6.png" src="/upload/getfiles/default/2022/11/15/20221115091111710.jpg" width="947" height="193" />
650) this.width=650;" title="07.png" src="/upload/getfiles/default/2022/11/15/20221115091112281.jpg" width="736" height="48" />
进行
vi
编辑器编辑区域
benet.com.zone
设置合格完全域名
650) this.width=650;" title="7.jpg" src="/upload/getfiles/default/2022/11/15/20221115091112654.jpg" width="723" height="268" />
在把
benet.com.zone
复制成
accp.com.zone,
在用
ls -l
查看下权限
650) this.width=650;" title="08.png" src="/upload/getfiles/default/2022/11/15/20221115091113119.jpg" />
进行
vi
编辑器编辑
,
跟
benet
一样,只是把域名换一下
650) this.width=650;" title="8.png" src="/upload/getfiles/default/2022/11/15/20221115091113755.jpg" width="633" height="42" />
650) this.width=650;" title="09.jpg" src="/upload/getfiles/default/2022/11/15/20221115091114040.jpg" />
开启服务,并且用
dns
解析下,想要解析必须给自己指定一个DNS地址
650) this.width=650;" title="9.png" src="/upload/getfiles/default/2022/11/15/20221115091114386.jpg" />
在回到宿主机上用域名登录网站
650) this.width=650;" title="20.jpg" src="/upload/getfiles/default/2022/11/15/20221115091115094.jpg" width="726" height="332" />
650) this.width=650;" title="21.jpg" src="/upload/getfiles/default/2022/11/15/20221115091115483.jpg" width="728" height="370" />
3.
基于端口虚拟主机
cd 到 conf.d
下面查看下
650) this.width=650;" title="1.png" src="/upload/getfiles/default/2022/11/15/20221115091115863.jpg" width="735" height="91" />
进入
vi
编辑器里添加一个端口
8080
650) this.width=650;" title="2.png" src="/upload/getfiles/default/2022/11/15/20221115091116165.jpg" />
在
opt
下面创建
benet01
的文件,然后在定义文字在
/opt/benet01/index.html
650) this.width=650;" title="3.png" src="/upload/getfiles/default/2022/11/15/20221115091116719.jpg" width="734" height="53" />
添加监听
Listen
端口
650) this.width=650;" title="6.png" src="/upload/getfiles/default/2022/11/15/20221115091117044.jpg" />
开启服务
650) this.width=650;" title="5.png" src="/upload/getfiles/default/2022/11/15/20221115091117564.jpg" width="743" height="119" />
看下端口监听
650) this.width=650;" title="7.png" src="/upload/getfiles/default/2022/11/15/20221115091118022.jpg" />
在回到宿主机上输入ip地址
650) this.width=650;" title="8.png" src="/upload/getfiles/default/2022/11/15/20221115091118461.jpg" width="745" height="365" />
实
验
完
成
原文:http://humajun.blog.51cto.com/9520388/1620105