httpd配置虛擬機器主機及存取控制

來源:互聯網
上載者:User

標籤:httpd apatche 虛擬機器主機

一、虛擬機器主機是在一台物理伺服器上配置多個網站,有三種實現方法:基於ip,基於連接埠,基於網域名稱


 配置虛擬機器主機建議在單獨一個檔案,並在主設定檔使用 include "xxx" 包含進來,這樣使配置件更清晰


  1. 基於連接埠:應先在主設定檔中增加一個監聽的連接埠listen 8080

    <virtualhost 172.16.168.140:80>

      options none

      documentroot "/var/www/80"

    </virtualhost>

    

    <virtualhost 172.16.168.140:8080>

      options none

      documentroot "/var/www/8080"

    </virtualhost>

 2.基於IP:

    <virtualhost 172.16.168.150:80>

     options none

     documentroot "/var/www/ip150"

    </virtualhost>

 3.基於網域名稱:apatche2.2版本應先在虛擬機器主機設定檔增加 namevirtualhost 172.16.168.140:80

   如果想通過多個網域名稱訪問到同一個網站,可以定義多個servername

    <virtualhost 172.16.168.140:80>

      servername www.a.com

      servername www.an.com

      options none

      documentroot "/var/www/a.com"

    </virtualhost>

    

    <virtualhost 172.16.168.140:80>

      servername www.b.com

      options noe

      documentroot "/var/www/b.com"

    </virtualhost>

二、配置使用者對web資源的存取控制:如果某些資源不想被使用者訪問,可以通過建立授權讓使用者訪問或根據ip地址進行限制

    通過建立授權:

     1.使用htpasswd 命令建立使用者名稱和密碼檔案: htpasswd -c /etc/httpd/conf/htpasswd zzc (注意:當需要建立第二個使用者時,去掉-c選項,否則會把第一次建立的使用者給清除掉)

     <directory "/var/www/secret">

      authtype basic

      authname "is a sceret..."

      authuserfile "/etc/httpd/conf/htpasswd"

      require (user abc | valid-user) valid-user指全部使用者 user可以指定具體某個使用者

     </directory>

     如果想通過組來管理,需先建立一個組檔案:

     650) this.width=650;" src="http://s3.51cto.com/wyfs02/M00/4D/F7/wKiom1Rd25Sj65pSAAAa1LzyUD4957.jpg" title=" - 2014年11月08日 - 16時59分28秒.png" alt="wKiom1Rd25Sj65pSAAAa1LzyUD4957.jpg" />

     然後在檔案中寫上組名和已經(使用htpasswd)建立好的使用者:

     650) this.width=650;" src="http://s3.51cto.com/wyfs02/M01/4D/F6/wKioL1Rd3JaRBY8BAAAW40-im9Q144.jpg" title=" - 2014年11月08日 - 17時01分55秒.png" alt="wKioL1Rd3JaRBY8BAAAW40-im9Q144.jpg" />

     最後在<directory>中增加下面兩條命令:

     authgroupfile "/etc/httpd/conf/htgroup"

     require group myuser


    通過限定ip地址:

     <directory "/var/www/secret“>

      order deny,allow

      deny from 192.168.100.1

     </directory>

    order指定 先拒絕後允許 或 先允許後拒絕

    先拒絕後允許:預設允許,如果不指定拒絕的地址將允許所有地址

    先允許後拒絕:預設拒絕,如果不指定允許的地址將拒絕所有地址

    地址可以是 主機名稱、網段(172.16.0.0 可以簡寫為172.16)、具體某個ip地址

    地址之間用逗號隔開

本文出自 “好記性不如敲鍵盤” 部落格,請務必保留此出處http://8718813.blog.51cto.com/8708813/1574423

httpd配置虛擬機器主機及存取控制

聯繫我們

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