打开bin\apache\Apache2.2.17\conf\httpd.conf
第61行:LoadModule alias_module modules/mod_alias.so 前面是否有#,如果有,去除这句话前面的# (开启alias的支持)
第446行:#Include conf/extra/httpd-vhosts.conf 去掉前面的# (使apache能够读取extra/httpd-vhosts.conf 文件)
打开bin\apache\Apache2.2.17\conf\extra\httpd-vhosts.conf
删除底部默认的一些配置:
之后根据下述添加多站点的方式,选择一种自己进行添加:
1、多IP多端口多站点配置
Listen 172.20.30.40:80
Listen 172.20.30.40:8080
Listen 172.20.30.50:80
Listen 172.20.30.50:8080
<VirtualHost 172.20.30.40:80>
DocumentRoot /www/example1-80
ServerName www.example1.com
</VirtualHost>
<VirtualHost 172.20.30.40:8080>
DocumentRoot /www/example1-8080
ServerName www.example1.com
</VirtualHost>
<VirtualHost 172.20.30.50:80>
DocumentRoot /www/example2-80
ServerName www.example1.org
</VirtualHost>
<VirtualHost 172.20.30.50:8080>
DocumentRoot /www/example2-8080
ServerName www.example2.org
</VirtualHost>
————————————————————
2、多IP单端口多站点
———————————————————–
<VirtualHost 192.168.1.1:80>
DocumentRoot "/usr/local/apache/a"
ServerName www.a.com #网站根目录
ServerAlias a.com #做出响应的域名,其实也就是这里列出的域名,也指向前面设置的网站根目录
DirectoryIndex index.html index.php
</VirtualHost>
NameVirtualHost 192.168.1.2:80
<VirtualHost 192.168.1.2:80>
DocumentRoot "/usr/local/apache/b"
ServerName www.b.com
ServerAlias b.com
DirectoryIndex index.php
</VirtualHost>
<VirtualHost 192.168.1.2:80>
DocumentRoot "/usr/local/apache/c"
ServerName www.c.com
ServerAlias c.com
DirectoryIndex index.php
</VirtualHost>
—————————————————————
3、单IP单端口多站点
—————————————————————
Listen 80
NameVirtualHost 192.168.1.15 #接收请求的IP地址
<VirtualHost 192.168.1.15> #绑定的ip
DocumentRoot "D:/Inetpub/www/maidou/" #网站目录
ServerName www.test.com #主机名(域名)
DirectoryIndex index.php #主目录默认页
ServerAlias test.other.com admin.other.com #做出响应的域名
ErrorLog logs/error_log.log #错误日志
CustomLog logs/custom.log common #用户日志
<Directory "D:/Inetpub/www/maidou/">
Options Indexes FollowSymLinks
AllowOverride All #AllowOverride指明Apache服务器是否加载.htacess
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
# 多台可以再添加
<VirtualHost 192.168.1.15>
DocumentRoot "D:/Inetpub/www/other/"
ServerName www.other.com
<Directory "D:/Inetpub/www/other/">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
根据自己的需要设置即可,除了DocumentRoot、ServerName是必须的外,其他几个设置都可以不要。