apche支持3种类型虚拟主机:
基于IP的虚拟主机
基于端口的虚拟主机
基于主机名的虚拟主机
一、基于IP虚拟主机
[root@localhost conf.d]# vi virtualhost.conf
<Directory "/data">
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
<VirtualHost 192.168.95.10:80>
DocumentRoot /data/web1
ServerName 192.168.95.10
ErrorLog /data/web1/logs/error_log
CustomLog /data/web1/logs/access_log combined
</VirtualHost>
<VirtualHost 192.168.95.11:80>
DocumentRoot /data/web2
ServerName 192.168.95.11
ErrorLog /data/web2/logs/error_log
CustomLog /data/web2/logs/access_log combined
</VirtualHost>
二、基于端口
1、修改主配置文件
#Listen 80
Listen 192.168.95.11:80
Listen 192.168.95.11:81
2、修改虚拟主机文件
<Directory "/data">
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
<VirtualHost 192.168.95.11:80>
DocumentRoot /data/web1
ServerName 192.168.95.11
ErrorLog /data/web1/logs/error_log
CustomLog /data/web1/logs/access_log combined
</VirtualHost>
<VirtualHost 192.168.95.11:81>
DocumentRoot /data/web2
ServerName 192.168.95.11
ErrorLog /data/web2/logs/error_log
CustomLog /data/web2/logs/access_log combined
</VirtualHost>
三、基于名称的虚拟主机
<Directory "/data">
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
<VirtualHost 192.168.95.11:80>
DocumentRoot /data/web1
ServerName [www.uplook.com](http://www.uplook.com/)
ErrorLog /data/web1/logs/error_log
CustomLog /data/web1/logs/access_log combined
</VirtualHost>
<VirtualHost 192.168.95.11:80>
DocumentRoot /data/web2
ServerName [www.uplooking.com](http://www.uplooking.com/)
ErrorLog /data/web2/logs/error_log
CustomLog /data/web2/logs/access_log combined
</VirtualHost>
网友评论