httpd虚拟主机实现

基于端口的实现

[root@localhost httpd]# cat conf.d/test.conf
<VirtualHost *:80>
	DocumentRoot /data/html/a
	<Directory "/data/html/a">
		Options none
		Allowoverride none
		Require all granted
	</Directory>
</VirtualHost>

<VirtualHost *:8080>
	DocumentRoot /data/html/b
	<Directory "/data/html/b">
		Options none
		Allowoverride none
		Require all granted
	</Directory>
</VirtualHost>

在这里插入图片描述
在这里插入图片描述

基于主机名的访问

[root@localhost httpd]# cat conf.d/test.conf
<VirtualHost *:80>
	DocumentRoot "/data/html/a"
	ServerName "www.a.com"
	<Directory "/data/html/a">
		Options none
		Allowoverride none
		Require all granted
	</Directory>
</VirtualHost>

<VirtualHost *:80>
	DocumentRoot "/data/html/b"
	ServerName "www.b.com"
	<Directory "/data/html/b">
		Options none
		Allowoverride none
		Require all granted
	</Directory>
</VirtualHost>

在这里插入图片描述

在这里插入图片描述

基于ip地址的访问

[root@localhost httpd]# cat conf.d/test.conf
<VirtualHost 192.168.199.243:80>
	DocumentRoot "/data/html/a"
	ServerName "www.a.com"
	<Directory "/data/html/a">
		Options none
		Allowoverride none
		Require all granted
	</Directory>
</VirtualHost>

<VirtualHost 192.168.192.128:80>
	DocumentRoot "/data/html/b"
	ServerName "www.b.com"
	<Directory "/data/html/b">
		Options none
		Allowoverride none
		Require all granted
	</Directory>
</VirtualHost>

在这里插入图片描述

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_44564366/article/details/104904159