Apache 2.4虛擬機器主機配置

來源:互聯網
上載者:User

標籤:apache   virtual hosts   

虛擬機器主機指的是在單一機器上運行多個網站 (例如 company1.example.com 和company2.example.com) 。 虛擬機器主機可以“基於 IP”,即每個 IP 一個網站; 或者“基於名稱”, 即每個 IP 多個網站。這些網站運行在同一物理伺服器上的事實不會明顯的透漏給終端使用者。——這是官網解釋。


配置Apache虛擬機器主機。(httpd-vhosts.conf —— Apache虛擬機器主機設定檔)

基於名稱的虛擬機器主機 (每個 IP 多個網站)

<VirtualHost *:80>    # This first-listed virtual host is also the default for *:80    ServerName www.example.com    ServerAlias example.com     DocumentRoot /www/domain</VirtualHost><VirtualHost *:80>    ServerName other.example.com    DocumentRoot /www/otherdomain</VirtualHost>

名詞解釋:

VirtualHost:指虛擬機器主機的IP/網域名稱,*:80代表所有代表所有80連接埠的IP

ServerName:虛擬機器主機名稱

ServerAlias:虛擬機器主機別名,主機別名可以是多個支援萬用字元

ServerAlias example.com *.example.com

DocumentRoot:網站目錄



基於 IP 的虛擬機器主機 (每個 IP 一個網站)

Listen 172.20.30.40:80<VirtualHost 172.20.30.40:80>    ServerAdmin [email protected]    DocumentRoot /www/vhosts/www1    ServerName www1.example.com    ErrorLog /www/logs/www1/error_log    CustomLog /www/logs/www1/access_log combined</VirtualHost> <pre name="code" class="plain">Listen 172.20.30.50:80<VirtualHost 172.20.30.50:80>    ServerAdmin [email protected]    DocumentRoot /www/vhosts/www2    ServerName www2.example.org    ErrorLog /www/logs/www2/error_log    CustomLog /www/logs/www2/access_log combined</VirtualHost>


 

名詞解釋:

<pre name="code" class="plain">ServerAdmin  網站管理員郵箱<pre name="code" class="plain"><pre name="code" class="plain">ErrorLog  錯誤記錄檔<pre name="code" class="plain"><pre name="code" class="plain">CustomLog  訪問日誌


 

 

 

 

開啟Apache虛擬機器主機功能(httpd.conf)

搜尋Virtual hosts,去掉#Include conf/extra/httpd-vhosts.conf前面的#

# Virtual hosts#Include conf/extra/httpd-vhosts.conf

重啟Apache服務


Apache 2.4虛擬機器主機配置

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.