实验:基于PORT的多虚拟主机配功能
- 实验环境:
网站服务器:192.168.99.101
客户机:192.168.99.102
#关闭防火墙和selinux,以免有其它因素
[101]$ setenforce 0
[101]$ iptables -F
- 安装httpd
[101]$ yum install httpd
- 创建多个网站目录
[101]$ mkdir -pv /data/{a,b,c}_site
- 创建每个网站的主页
[101]$ echo "<h1> webA page </h1>" > /data/a_site/index.html
[101]$ echo "<h1> webB page </h1>" > /data/b_site/index.html
[101]$ echo "<h1> webC page </h1>" > /data/c_site/index.html
- 编辑配置文件
#这里的配置文件是单独写在了vhostport.conf里
[101]$ cat /etc/httpd/conf.d/test_port.conf
listen 8001
listen 8002
listen 8003
<virtualhost *:8001>
documentroot /data/a_site
<directory /data/a_site>
require all granted
</directory>
</virtualhost>
<virtualhost *:8002>
documentroot /data/b_site
<directory /data/b_site>
require all granted
</directory>
</virtualhost>
<virtualhost *:8003>
documentroot /data/c_site
<directory /data/c_site>
require all granted
</directory>
</virtualhost>
- 搞定了,重启服务吧
[101]$ systemctl start httpd
- 测试下吧
[102]$ curl 127.0.0.1:8001
<h1> webA page </h1>
[102]$ curl 127.0.0.1:8002
<h1> webB page </h1>
[102]$ curl 127.0.0.1:8003
<h1> webC page </h1>
实验:基于 ip 的多虚拟主机配功能
- 实验环境:
网站服务器:192.168.99.101
客户机:192.168.99.102
#关闭防火墙和selinux,以免有其它因素
[101]$ setenforce 0
[101]$ iptables -F
- 安装httpd
[101]$ yum install httpd
- 创建多个网站目录
[101]$ mkdir -pv /data/{a,b,c}_site
- 创建每个网站的主页
[101]$ echo "<h1> webA page </h1>" > /data/a_site/index.html
[101]$ echo "<h1> webB page </h1>" > /data/b_site/index.html
[101]$ echo "<h1> webC page </h1>" > /data/c_site/index.html
- 添加多个ip
[101]$ ip a a 192.168.99.201 dev eth0
[101]$ ip a a 192.168.99.202 dev eth0
[101]$ ip a a 192.168.99.203 dev eth0
[101]$ ip a
...
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:34:14:99 brd ff:ff:ff:ff:ff:ff
inet 192.168.99.101/24 brd 192.168.99.255 scope global noprefixroute eth0
valid_lft forever preferred_lft forever
inet 192.168.99.201/32 scope global eth0
valid_lft forever preferred_lft forever
inet 192.168.99.202/32 scope global eth0
valid_lft forever preferred_lft forever
inet 192.168.99.203/32 scope global eth0
valid_lft forever preferred_lft forever
inet6 fe80::78db:abfc:b139:b7ac/64 scope link noprefixroute
valid_lft forever preferred_lft forever
- 编辑配置文件
#这里的配置文件是单独写在了vhostport.conf里
[101]$ cat /etc/httpd/conf.d/test_port.conf
<virtualhost 192.168.99.201:80>
documentroot /data/a_site
<directory /data/a_site>
require all granted
</directory>
</virtualhost>
<virtualhost 192.168.99.202:80>
documentroot /data/b_site
<directory /data/b_site>
require all granted
</directory>
</virtualhost>
<virtualhost 192.168.99.203:80>
documentroot /data/c_site
<directory /data/c_site>
require all granted
</directory>
</virtualhost>
- 搞定了,重启服务吧
[101]$ systemctl start httpd
- 测试下吧
[102]$ curl 127.0.0.1:8001
<h1> webA page </h1>
[102]$ curl 127.0.0.1:8002
<h1> webB page </h1>
[102]$ curl 127.0.0.1:8003
<h1> webC page </h1>
实验:基于 FQDN 的多虚拟主机配功能
- 实验环境:
网站服务器:192.168.99.101
客户机:192.168.99.102
#关闭防火墙和selinux,以免有其它因素
[101]$ setenforce 0
[101]$ iptables -F
- 安装httpd
[101]$ yum install httpd
- 创建多个网站目录
[101]$ mkdir -pv /data/{a,b,c}_site
- 创建每个网站的主页
[101]$ echo "<h1> webA page </h1>" > /data/a_site/index.html
[101]$ echo "<h1> webB page </h1>" > /data/b_site/index.html
[101]$ echo "<h1> webC page </h1>" > /data/c_site/index.html
- 编辑配置文件
#这里的配置文件是单独写在了vhostport.conf里
[101]$ cat /etc/httpd/conf.d/test_port.conf
<virtualhost *:80>
documentroot /data/web01
servername www.web01.com
<directory /data/web01>
require all granted
</directory>
CustomLog "logs/a_access_log" combined
</virtualhost>
<virtualhost *:80>
documentroot /data/web02
servername www.web02.com
<directory /data/web02>
require all granted
</directory>
CustomLog "logs/a_access_log" combined
</virtualhost>
<virtualhost *:80>
documentroot /data/web03
servername www.web03.com
<directory /data/web03>
require all granted
</directory>
CustomLog "logs/a_access_log" combined
</virtualhost>
- 搞定了,重启服务吧
[101]$ systemctl start httpd
- 测试前要设置下hosts,要不就搭一个DNS
[102]$ vim /etc/hosts
192.168.99.101 www.asite.com www.bsite.com www.csite.com
- 测试下吧
[102]$ curl 127.0.0.1:8001
<h1> webA page </h1>
[102]$ curl 127.0.0.1:8002
<h1> webB page </h1>
[102]$ curl 127.0.0.1:8003
<h1> webC page </h1>