【技术宅7】一个或多个虚拟主机配置方法

一、虚拟主机配置方法

       1,在文件C:/windows/system32/drivers/etc/hosts 加上 

              127.0.0.1   你的域名 

      

       2,在 httpd.conf里的去掉#

          Include conf/extra/httpd-vhosts.conf

        

       3,在apache目录里找到 conf/extra/httpd-vhosts.conf 把里面的内容都注释(每一行前面加 #)然后添加后面的代码:

               NameVirtualHost *:80  

               <VirtualHost 127.0.0.1:80>

                     ServerAdmin admin@admin.com     #你的邮箱地址 

                     DocumentRoot "C:/www.a.com"     # 配置域名对应的文件夹路径

                     ServerName www.a.com            #配置对应的域名 

               

                     <Directory "C:/www.a.com">      <--配置文件夹相关权限

                            Options Indexes FollowSymLinks

                            AllowOverride None

                            Order allow,deny

                            Allow from all

                     </Directory>                    -->

             

                     ErrorLog "logs/www.a.com-error.log"

                     CustomLog "logs/www.a.com-access.log" common

              </VirtualHost>

 

二、一个ip绑定多个域名  

       方法一:通过端口来区分不同的站点

                     ?与配置虚拟主机一样先配置一个站点

                     1、启用在 httpd.conf 里的Include conf/extra/httpd-vhosts.conf ,即把前面的#去掉  // Virtual hosts 虚拟主机的意思                 

                     2、在windows下面的host文件:C:/windows/system32/drivers/etc/hosts 添加域名 //127.0.0.1 www.a.html               

                     3、在Apache2.2\conf\extra目录下打开httpd-vhosts.conf文件,在里面进行如下配置

                            <VirtualHost 127.0.0.1:80>

                                   DocumentRoot “d:/myblog”

                                   DirectoryIndex index.html    

                                     <Directory "C:/www.a.com">    

                                          Options Indexes FollowSymLinks

                                          AllowOverride None 

                                          Order allow,deny   

                                          Allow from all

                                   </Directory>            

                            </VirtualHost>

                           

                     ?配置第二个站点

                     1、在Apache2.2\conf\extra目录下打开httpd-vhosts.conf文件,在里面进行如下配置

                            <VirtualHost 127.0.0.1:81>

                                   DocumentRoot “d:/myweb”

                                   DirectoryIndex index.html    

                                     <Directory "C:/www.a.com">    

                                          Options Indexes FollowSymLinks

                                          AllowOverride None 

                                          Order allow,deny   

                                          Allow from all

                                   </Directory>            

                            </VirtualHost>

                     2、让apache监听81端口,即在apache的httpd.conf中的listen添加:Listen 81

                     3、在windows下面的host文件:C:/windows/system32/drivers/etc/hosts 添加域名 //127.0.0.1 www.b.html

                            【注意:以端口区分的话,在浏览器输入地址时,需要在地址后面输入端口,否则无法执行】

      

      

       方法二:通过ServerName端区分不同的站点

                     第一步:站点名称上面的一样

                            d:/myblog   www.a.html

                            d:/myweb   www.b.html

                           

                     第二步:在httpe-vhosts.conf中配置

                     <VirtualHost *:80>                       //这里的127.0.0.1要改成*

                            DocumentRoot “d:/myblog”

                            ServerName www.a.html

                            DirectoryIndex index.html    

                        <Directory "C:/www.a.com">    

                              Options Indexes FollowSymLinks

                              AllowOverride None 

                              Order allow,deny   

                              Allow from all

                       </Directory>            

                     </VirtualHost>

             

                     <VirtualHost *:81>                       //这里的127.0.0.1要改成*

                        DocumentRoot “d:/myweb”

                        ServerName www.b.html

                        DirectoryIndex index.html    

                        <Directory "C:/www.b.com">    

                             Options Indexes FollowSymLinks

                             AllowOverride None 

                             Order allow,deny   

                             Allow from all

                        </Directory>            

                     </VirtualHost>

                           

                 第三步:在windows下面的host文件:C:/windows/system32/drivers/etc/hosts  添加你的域名

                     127.0.0.1 www.a.html

                     127.0.0.1 www.b.html

posted @ 2014-09-21 19:38  来自星星的bug  阅读(287)  评论(0编辑  收藏  举报