Apache设置多端口,多IP映射多站点

实验目的:

koastal.com:90 映射到 127.0.0.1:90 ,对应路径 D:\schooloes

naruto.com 映射到 127.0.0.10 , 对应路径 E:\demo

实验步骤:


1. 通过修改host进行域名劫持

hosts文件位置:C:\Windows\System32\drivers\etc\hosts

在文件最后添加以下内容:

127.0.0.1     koastal.com
127.0.0.1     www.koastal.com
127.0.0.10      naruto.com
127.0.0.10      www.naruto.com


2. 开启Virtual hosts

httpd.conf文件位置:C:\wamp\bin\apache\apache2.4.9\conf\httpd.conf

定位到:

# Virtual hosts
#Include conf/extra/httpd-vhosts.conf

去掉注释符,修改为:

# Virtual hosts
Include conf/extra/httpd-vhosts.conf


3. 开启端口监听

打开文件httpd.conf,定位到位置:

Listen 0.0.0.0:80
Listen [::0]:80

在下面添加一行

Listen 90


4. 设置端口映射

将httpd-vhosts.conf 内容清空,然后添加:

<VirtualHost 127.0.0.1:90>
    ServerAdmin [email protected]
    DocumentRoot "d:/schooloes"
    ServerName koastal.com
    ServerAlias www.koastal.com
    ErrorLog "logs/koastal.com-error.log"
    CustomLog "logs/koastal.com-access.log" common
	<Directory "d:/schooloes">
		Options FollowSymLinks
		AllowOverride None
		Order deny,allow
		Require all granted
	</Directory>
</VirtualHost>

5. 设置IP映射

打开httpd-vhosts.conf ,然后添加:

<VirtualHost 127.0.0.10:80>
    ServerAdmin [email protected]
    DocumentRoot "e:/demo"
    ServerName naruto.com
    ServerAlias www.naruto.com
    ErrorLog "logs/naruto.com-error.log"
    CustomLog "logs/naruto.com-access.log" common
	<Directory "e:/demo">
		Options Indexes #不存在默认页面时,显示目录
		AllowOverride None #不使用.htaccess,提高性能
		Order deny,allow #顺序是先deny,然后allow
		Require all granted
	</Directory>
</VirtualHost>


你可能感兴趣的:(Apache设置多端口,多IP映射多站点)