apache 虛擬主機配置(根據不同的域名映射到不同網站)


  最近弄了台香港服務器做測試,Web服務器軟件用的是Apache2.2,機器只有一台,ip只有一個,但是想測試幾個站點,於是嘗試了下Apache的虛擬主機配置。之前已經寫過一篇博文了——《Apache 根據不同的端口 映射不同的站點》,但是,今天在學習微信公眾平台的時候,由於微信公眾平台只支持80端口,所以無奈,只能嘗試根據不同的域名映射不同的站點。

  

一、修改httpd.conf

  打開Apache的目錄,找到httpd.conf文件,分別去掉下面兩行文字前面的#號。

 

 #LoadModule vhost_alias_module modules/mod_vhost_alias.s
 #Include conf/extra/httpd-vhosts.conf

二、修改httpd-vhosts.conf

打開該文件,看到以下類似內容。虛擬主機的配置也是參照以下內容配置。下面對該內容進行講解

<VirtualHost 59.188.244.204>
    ServerAdmin webmaster@dummy-host.www.ronghui66.com
    DocumentRoot "C:/Program Files/Apache Software Foundation/Apache2.2/htdocs"
    ServerName ronghui66.com:80
    
<Directory "C:/Program Files/Apache Software Foundation/Apache2.2/htdocs">
    #
    # Possible values for the Options directive are "None", "All",
    # or any combination of:
    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #
    # Note that "MultiViews" must be named *explicitly* --- "Options All"
    # doesn't give it to you.
    #
    # The Options directive is both complicated and important.  Please see
    # http://httpd.apache.org/docs/2.2/mod/core.html#options
    # for more information.
    #
    Options Indexes FollowSymLinks

    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   Options FileInfo AuthConfig Limit
    #
    AllowOverride None

    #
    # Controls who can get stuff from this server.
    #
    Order allow,deny
    Allow from all

</Directory>
    
#    ServerAlias www.dummy-host.www.ronghui66.com
    ErrorLog "logs/bocai-error.log"
    CustomLog "logs/bocai-access.log" common
</VirtualHost>


#
# 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 59.188.244.204>
    ServerAdmin webmaster@dummy-host.www.ronghui66.com
    DocumentRoot "D:/wwwroot/weixin"
    ServerName 0735wmw.com:80
    
<Directory "D:/wwwroot/weixin">
    #
    # Possible values for the Options directive are "None", "All",
    # or any combination of:
    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #
    # Note that "MultiViews" must be named *explicitly* --- "Options All"
    # doesn't give it to you.
    #
    # The Options directive is both complicated and important.  Please see
    # http://httpd.apache.org/docs/2.2/mod/core.html#options
    # for more information.
    #
    Options Indexes FollowSymLinks

    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   Options FileInfo AuthConfig Limit
    #
    AllowOverride None

    #
    # Controls who can get stuff from this server.
    #
    Order allow,deny
    Allow from all

</Directory>
    
#    ServerAlias www.dummy-host.www.ronghui66.com
    ErrorLog "logs/weixin-error.log"
    CustomLog "logs/weixin-access.log" common
</VirtualHost>

ServerAdmin 管理員郵箱

DocumentRoot 網站目錄 (注意:如果網站目錄中的路徑有空格,請在路徑兩端加上雙引號)

ServerName 要綁定的域名(必填)


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM