Web 伺服器(第一版-續)-Name-based Virtual Host

此篇文章是將Virtual Hosts的設定寫成conf組態檔,儲存在/etc/httpd/conf.d路徑下,Apache啟動時會自動載入,和C語言載入函數庫觀念相同,可減少主程式碼的長度。
伺服器-Name-based Virtual Host

將/etc/httpd/conf/httpd.conf的VirtualHost相關設定移動/etc/httpd/conf.d/vhost.conf 編輯 Apache 組態檔
# vim /etc/httpd/conf.d/vhost.conf
 NameVirtualHost *:80

 <VirtualHost *:80>  // 此區塊設定可以省略
   DocumentRoot /var/www/html
   ServerName apacheserver139.example.com
 </VirtualHost>

 <VirtualHost *:80>
   DocumentRoot /var/www/vhost
   ServerName vhostapacheserver139.example.com
 </VirtualHost>

 <VirtualHost *:80>
   DocumentRoot /var/www/svhost
   ServerName secretapacheserver139.example.com
   <Directory /var/www/svhost>
      AuthName "Secret Hideout"
      AuthType basic  // 傳輸過程不加密,因此最好搭配 ssl 才安全。
      AuthUserFile /var/www/svhost/users
      require valid-user
   </Directory>
 </VirtualHost>

重啟 Apache
# service httpd restart

沒有留言:

張貼留言