apache下多網站的架設

來源:互聯網
上載者:User

這裡是指同一IP綁定N個網域名稱,有二種方式實現
方法1、僅修改httpd.conf
假設二個網域名稱bbs.xxx.com與blog.xxx.com
開啟httpd.conf
將檔案拖到最下面,加上

  1. <VirtualHost *:80>  
  2.  ServerName bbs.xxx.com   #網域名稱   
  3.  DocumentRoot "F:/website/bbs"   #該網域名稱對應的目錄位址     
  4. <Directory "F:/website/bbs">   #該節點是配置許可權、預設首頁啊等等東東。   
  5.  Options FollowSymLinks IncludesNOEXEC Indexes   
  6.  DirectoryIndex  index.php    
  7.  AllowOverride None    
  8.  Order Deny,Allow    
  9.  Allow from all       
  10. </Directory>  
  11. </VirtualHost>  
  12.   
  13. <VirtualHost *:80>  
  14.  ServerName blog.xxx.com   
  15.  DocumentRoot "D:/PHPSite/wordpress"   
  16. <Directory "D:/PHPSite/wordpress">    
  17.  Options FollowSymLinks IncludesNOEXEC Indexes   
  18.  DirectoryIndex  index.php    
  19.  AllowOverride None    
  20.  Order Deny,Allow    
  21.  Allow from all    
  22. </Directory>  
  23. </VirtualHost>  

重啟apache,就OK啦。當然你要修改你的hosts檔案。

方法2、修改\PhpServer\Apache2.2\conf\extra\httpd-vhosts.conf
直接將上面一段copy到httpd-vhosts.conf的最後即可。
實際上看名字就知道httpd-vhosts.conf是一個虛擬網站配置集中地,方便管理。
也就是如下:

#  
# Virtual Hosts  
#  
# If you want to maintain multiple domains/hostnames on your  
# machine you can setup VirtualHost containers for them. Most configurations  
# use only name-based virtual hosts so the server doesn't need to worry about  
# IP addresses. This is indicated by the asterisks in the directives below.  
#  
# Please see the documentation at   
# <http://httpd.apache.org/docs/2.2/vhosts/> 
# for further details before you try to setup virtual hosts.  
#  
# You may use the command line option '-S' to verify your virtual host  
# configuration.  
 
#  
# Use name-based virtual hosting.  
#  
NameVirtualHost *:80  
 
#  
# VirtualHost example:  
# Almost any Apache directive may go into a VirtualHost container.  
# The first VirtualHost section is used for all requests that do not  
# match a ServerName or ServerAlias in any <VirtualHost> block.  
#  
 
 
<VirtualHost *:80> 
 ServerName bbs.xxx.com   #網域名稱  
 DocumentRoot "F:/website/bbs"   #該網域名稱對應的目錄位址    
<Directory "F:/website/bbs">   #該節點是配置許可權、預設首頁啊等等東東。  
 Options FollowSymLinks IncludesNOEXEC Indexes  
 DirectoryIndex  index.php   
 AllowOverride None   
 Order Deny,Allow   
 Allow from all      
</Directory> 
</VirtualHost> 
 
 
<VirtualHost *:80> 
 ServerName blog.xxx.com  
 DocumentRoot "D:/PHPSite/wordpress"  
<Directory "D:/PHPSite/wordpress">   
 Options FollowSymLinks IncludesNOEXEC Indexes  
 DirectoryIndex  index.php   
 AllowOverride None   
 Order Deny,Allow   
 Allow from all   
</Directory> 
</VirtualHost> 

重啟apache。
如果不行的話,看你的httpd.conf是否啟用了vhost
開啟httpd.conf,找到
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
看是否啟用,即去掉Include conf/extra/httpd-vhosts.conf前的#
重啟apache,爽去吧。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.