win 下 apache 虚拟主机配置方式

虚拟主机的配置在apache安装目录下/conf/extra/httpd-vhosts.conf文件中,需要在/conf/httpd.conf中开启。
LoadModule vhost_alias_module modules/mod_vhost_alias.so
Include conf/extra/httpd-vhosts.conf
1、基于IP地址的虚拟主机 (*服务器有多个IP地址)
<VirtualHost 192.168.1.1>
    DocumentRoot D:/wwwroot/site1
    ServerName www.site1.com
    <Directory "D:/wwwroot/site1">
         Options Indexes FollowSymLinks
     AllowOverride None
     Order allow,deny
     Allow From All
    </Directory>
</VirtualHost>

<VirtualHost 192.168.1.2>
    DocumentRoot D:/wwwroot/site2
    ServerName www.site2.com
    <Directory "D:/wwwroot/site2">
         Options Indexes FollowSymLinks
     AllowOverride None
     Order allow,deny
     Allow From All
    </Directory>
</VirtualHost>
2、基于IP地址和多端口 (*分别绑定8080和8088端口)
Listen 127.0.0.1:8080
<VirtualHost 127.0.0.1:8080>
    DocumentRoot D:/wwwroot/site1
    ServerName www.site1.com
</VirtualHost>

Listen 127.0.0.1:8088
<VirtualHost 127.0.0.1:8088>
    DocumentRoot D:/wwwroot/site2
    ServerName www.site2.com
</VirtualHost>
3、单IP地址基于域名的虚拟主机
Listen 80
NameVirtualHost *:80
<VirtualHost *:80>
    DocumentRoot D:/wwwroot/site1
    ServerName www.site1.com
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot D:/wwwroot/site2
    ServerName www.site2.com
</VirtualHost>
4、多IP地址基于域名的虚拟主机
<VirtualHost 192.168.1.1>
    DocumentRoot D:/wwwroot/site1
    ServerName www.site1.com
</VirtualHost>

<VirtualHost 192.168.1.2>
    DocumentRoot D:/wwwroot/site2
    ServerName www.site2.com
</VirtualHost>
5、多端口配置基于域名的虚拟主机
Listen 80
<VirtualHost *:80>
    DocumentRoot D:/wwwroot/site1
    ServerName www.site1.com
</VirtualHost>

Listen 8080
<VirtualHost *:8080>
    DocumentRoot D:/wwwroot/site2
    ServerName www.site2.com
</VirtualHost>
6、基于域名和基于IP 的混合虚拟主机
Listen 80
NameVirtualHost 192.168.1.1
<VirtualHost 192.168.1.1:80>
    DocumentRoot D:/wwwroot/site1
    ServerName www.site1.com
</VirtualHost>

Listen 8080
<VirtualHost 192.168.1.1:8080>
    DocumentRoot D:/wwwroot/site2
    ServerName www.site2.com
</VirtualHost>

 

 

相关文章

1、到apache官网上下载apache的安装文件 http://httpd.apache.org/download.cgi 点击链接Files for Mic...
1.确保apache已开启rewrite。 2.在.htaccess文件中添加如下: RewriteEngine On RewriteCond %{HTTP_RE...
在httpd.conf中修改ErrorLog和CustomLog的配置 ErrorLog &quot;|E:/apache2.2/bin/rotatelogs.exe ...
1、打开apache的配置文件httpd.conf,打开如下项 LoadModule proxy_module modules/mod_proxy.so LoadM...
一、下载必须的安装源码包 http://httpd.apache.org/download.cgi#apache24 httpd-2.4.23.tar.gz http:...
1.在apache配置文件httpd.conf中找到如下行: #LoadModule rewrite_module modules/mod_rewrite.so 去掉...