Apache 三种虚拟主机配置方式
https://blog.csdn.net/wanwanperfect/article/details/78332374
Apache 三种虚拟主机配置方式
1. 基于端口
1.1 配置
mkdir /data/site{1,2,3}
for i in 1 2 3;do echo site$i >/data/site$i/index.html;done
vim /etc/httpd/conf.d/vhosts.conf
listen 8001
listen 8002
listen 8003
<virtualhost *:8001>
documentroot /data/site1
<directory /data/site1>
require all granted
</directory>
</virtualhost>
<virtualhost *:8002>
<directory /data/site2>
require all granted
</directory>
documentroot /data/site2
</virtualhost>
<virtualhost *:8003>
<directory /data/site3>
require all granted
</directory>
documentroot /data/site3
</virtualhost>
1.2 测试
for m in 1 2 3;do curl localhost:800$m;done
2. 基于IP
2.1 配置
# 给网卡添加虚拟IP
for ip in 1 2 3;do ip a a 192.168.36.$ip dev eth0;done
vim /etc/httpd/conf.d/vhosts.conf
<virtualhost 192.168.36.1:80>
documentroot /data/site1
<directory /data/site1>
require all granted
</directory>
</virtualhost>
<virtualhost 192.168.36.2:80>
<directory /data/site2>
require all granted
</directory>
documentroot /data/site2
</virtualhost>
<virtualhost 192.168.36.3:80>
<directory /data/site3>
require all granted
</directory>
documentroot /data/site3
</virtualhost>
2.2 测试
for ip in 1 2 3; do curl 192.168.36.$ip;done
3. 基于域名
3.1 配置
vim /etc/httpd/conf.d/vhosts.conf
<virtualhost *:80>
documentroot /data/site1
servername www.1.com
<directory /data/site1>
require all granted
</directory>
CustomLog "logs/a_access_log" combined
</virtualhost>
<virtualhost *:80>
<directory /data/site2>
require all granted
</directory>
documentroot /data/site2
servername www.2.com
CustomLog "logs/b_access_log" combined
</virtualhost>
<virtualhost *:80>
servername www.2.com
<directory /data/site3>
require all granted
</directory>
documentroot /data/site3
CustomLog "logs/c_access_log" combined
</virtualhost>
3.2 测试
for n in 1 2 3; do echo 127.0.0.1 www.$n.com >>/etc/hosts;curl www.$n.com;done
本文来自博客园,作者:Jas0n0ss,转载请注明原文链接:https://www.cnblogs.com/Jas0n0ss/p/14324100.html