Apache 配置虚拟主机三种方式:(推荐第二种) 一、基于 IP
[root@localhost root]# ifconfig eth0:1 192.168.1.11
[root@localhost root]# ifconfig eth0:2 192.168.1.12
[root@localhost root]# ifconfig eth0:3 192.168.1.13
192.168.1.11 www.test1.com
192.168.1.12 www.test2.com
192.168.1.13 www.test3.com
/www/test1/1.html
/www/test2/2.html
/www/test3/3.html
<VirtualHost 192.168.1.11:80>
ServerName www.test1.com
DocumentRoot /www/test1/
</virtualhost><VirtualHost 192.168.1.12:80>
ServerName www.test1.com
DocumentRoot /www/test2/
</virtualhost><VirtualHost 192.168.1.13:80>
ServerName www.test1.com
DocumentRoot /www/test3/
</virtualhost>二、基于主机名
192.168.1.10 www.test1.com
192.168.1.10 www.test2.com
192.168.1.10 www.test3.com
/www/test1/1.html
/www/test2/2.html
/www/test3/3.html
NameVirtualHost *:80 <VirtualHost *:80>
ServerName *
DocumentRoot /www/
</virtualhost> <virtualhost *:80="">ServerName www.test1.com
DocumentRoot /www/test1/
</virtualhost><VirtualHost *:80=""> ServerName www.test2.com
DocumentRoot /www/test2/
</virtualhost> <virtualhost *:80=""> ServerName www.test3.comDocumentRoot /www/test3/
</virtualhost>三、基于端口
修改配置文件 将原来的 Listen 80 改为 Listen 80 Listen 8080
更改虚拟主机设置:
<VirtualHost 192.168.1.10:80>
DocumentRoot /var/www/test1/
ServerName www.test1.com
</virtualhost>
<VirtualHost 192.168.1.10:8080>
DocumentRoot /var/www/test2
ServerName www.test2.com
</virtualhost>
Ngix 配置方法:( ngix 配置简单 并发数高)
server { listen 80;
server_name www.test1.com;
root /data/www/html/www.test1.com;
index index.html index.htm index.php;
} server { listen 80;
server_name www.test2.com;
root /data/www/html/www.test2.com;
index index.html index.htm index.php;
}
1
imlonghao673 2016-10-11 12:03:12 +08:00 via Android
楼主你想干嘛?
|
2
wangzhangwei OP @imlonghao673 分享
|
3
EXE 2016-10-11 12:09:44 +08:00
还是 nginx 更方便一些
|
4
wangzhangwei OP @EXE 是的, apache 配置麻烦
|