1. 程式人生 > >LAMP虛擬主機配置(基於域名的虛擬主機)

LAMP虛擬主機配置(基於域名的虛擬主機)

虛擬主機配置包括兩種:基於域名的虛擬主機和基於IP的虛擬主機,一下主要說明“基於域名的虛擬主機”配置

  • 首先,在httpd.conf檔案中啟用虛擬主機配置檔案:

             # Virtual hosts 配置啟用虛擬主機
             Include conf/extra/httpd-vhosts.conf

  • 其次,在httpd-vhosts.conf檔案中首先要設定NameVirtualHost:

             # 原有NameVirtualHost 這裡影響配置結果,基於主機名的虛擬主機需要指定一個固定IP,否則域名目錄無效
             #NameVirtualHost *:80
             NameVirtualHost 127.0.0.1

  • 配置我們自己的虛擬主機:

           <VirtualHost 127.0.0.1:80>
                DocumentRoot "D:/Softwares/LAMP/WWW/inv"
                ServerName inv.com

                #這裡配置歡迎首頁面
                DirectoryIndex index.html index.htm index.php
                <Directory "D:/Softwares/LAMP/WWW/inv">
                    Options FollowSymLinks

                   #Options indexes FollowSymLinks
                    #不許可別人修改我們的頁面
                    AllowOverride None
                    #設定訪問許可權
                    Order allow,deny
                    Allow from all
                </Directory>
            </VirtualHost>

  •    修改hosts 檔案,新增如下內容:

                127.0.0.1         inv.com