天天看點

Web應用Ⅱ

Web應用Ⅱ

   1.虛拟主機

    基于httpd的虛拟主機有三種形式:基于IP,基于端口,基于主機名。

    下面介紹基于主機名的虛拟主機。

    首先,使用虛拟主機,需要取消中心主機,也就是注釋掉DocumentRoot行。

    然後,定義主機頭:NameVirtualHost 192.168.0.100:80

          <VirtualHost 192.168.0.100:80>

            ServerName virt1.com           //定義主機名

            DocumentRoot  /virt1            //定義虛拟主機的網站的網頁目錄

          </VirtualHost> 

            ServerName virt2.com          

            DocumentRoot  /virt2         

          </VirtualHost>

    另外,在使用基于端口的虛拟主機需要監聽相應的端口。使用Listen 端口号。

   2.使用.htaccess檔案,實作使用者通路時的身份認證

   #htpasswd -cm /etc/httpd/.htpasswd dongni   //用于建立帳号檔案,并為使用者dongni建立登入密碼。其中選項-c用于初次建立帳号檔案,建立後再使用-c表示覆寫原檔案。-m表示新增使用者。

   AuthName     "dongni's file"     //認證名

   AuthType     basic               //認證類型

   AuthUserFile   /etc/httpd/.htpasswd   //關聯認證使用的帳号檔案 

   require user  dongni                 //僅允許使用者dongni通路

   另外,也可以通過選項AuthGroupFile 實作組通路時的身份認證  

   3.加密的Web通路(https)

   Apache and SSL:基于TCP協定的443端口。

   在實作https時需要安裝子產品:mod_ssl,安裝後其配置檔案為:/etc/httpd/conf.d/ssl.conf

   在配置檔案中,關聯伺服器證書的行:SSLCertificateFIle:/etc/pki/tls/certs/your_host.crt

   關聯公鑰的行:SSLCertificateFile  /etc/pki/tls/localhost.key

繼續閱讀