其他分享
首页 > 其他分享> > httpd--虚拟主机

httpd--虚拟主机

作者:互联网

17、虚拟主机
站点标识: socket
	IP相同,但端口不同
	IP不同,但端口均为默认端口
	FQDN不同:请求报文中首部 Host: www.magedu.com

有三种实现方案:
	基于ip:为每个虚拟主机准备至少一个ip地址
	基于port:为每个虚拟主机使用至少一个独立的port
	基于FQDN:为每个虚拟主机使用至少一个FQDN(常用)
	
虚拟主机的配置方法:
	<VirtualHost IP:PORT>
		ServerName FQDN
		DocumentRoot “/path"
	</VirtualHost>
	建议:上述配置存放在独立的配置文件中
	其它可用指令:
		ServerAlias:虚拟主机的别名;可多次使用
		ErrorLog: 错误日志
		CustomLog:访问日志
		<Directory “/path"> </Directory>
		Alias
	
实验:基于IP的多虚拟主机
vim /etc/httpd/conf.d/test.conf
	<virtualhost 192.168.37.101:80>
		documentroot /data/asite
		CustomLog "logs/asite_access_log" combined
		<Directory "/data/asite">
			Require all granted:wqwq
		</Directory>
	</virtualhost>

	<virtualhost 192.168.37.102:80>
		documentroot /data/bsite
			CustomLog "logs/bsite_access_log" combined
		<Directory "/data/bsite">
			Require all granted
		</Directory>
	</virtualhost>

	<virtualhost 192.168.37.103:80>
		documentroot /data/csite
		CustomLog "logs/csite_access_log" combined
		<Directory "/data/csite">
			Require all granted
		</Directory>
	</virtualhost>

	vim /etc/hosts
	192.168.37.101  www.a.com  
	192.168.37.102  www.b.com 
	192.168.37.103  www.c.com

实验:基于port的多虚拟主机
vim /etc/httpd/conf/httpd.conf
	listen 81
	listen 82
	listen 83

vim /etc/httpd/conf.d/test.conf
	<virtualhost *:81>
		documentroot /data/asite
		<Directory "/data/asite">
			Require all granted
		</Directory>
	</virtualhost>
	
	<virtualhost *:82>
		documentroot /data/bsite
		<Directory "/data/bsite">
			Require all granted
		</Directory>
	</virtualhost>
	
	<virtualhost *:83>
		documentroot /data/csite
		<Directory "/data/csite">
			Require all granted
		</Directory>
	</virtualhost>

	vim /etc/hosts
	192.168.37.7 www.a.com  www.b.com www.c.com


实验: 基于主机头的多虚拟主机
vim /etc/httpd/conf.d/test.conf
	<virtualhost *:80>  
		documentroot /data/asite
		servername www.a.com
		<Directory "/data/asite">
			Require all granted
		</Directory>
	</virtualhost>

	<virtualhost *:80>
		documentroot /data/bsite
		servername www.b.com
		<Directory "/data/bsite">
			Require all granted
		</Directory>
	</virtualhost>

	<virtualhost *:80>
		documentroot /data/csite
		servername www.c.com
		<Directory "/data/csite">
			Require all granted
		</Directory>
	</virtualhost>	

  

标签:httpd,www,虚拟主机,--,data,Require,documentroot,com
来源: https://www.cnblogs.com/Yuanbangchen/p/16599623.html