apache虛擬主機跟虛擬目錄的配置與區別
阿新 • • 發佈:2018-11-25
首先,我對虛擬目錄的理解就是: 配置一個路徑訪問相應的專案所在地
其次,再是虛擬主機的理解就是: 配置域名或者埠到主機上訪問不同路徑下的專案(這裡主機可以是多個)
接著,先來看虛擬目錄吧!
一、先把httpd.conf裡的預設路徑給註釋掉,因為要自行定義目錄
二、找到IfModule模組,並且新增一個此模組,設定好歡迎頁,別名,也就是路徑對面的專案所在地名稱
如:Alias /web "D:/web" 意思是路徑/web對應的專案目錄在D盤的/web下面
<IfModule dir_module> DirectoryIndex index.html index.htm index.php Alias /web "D:/web" <Directory D:/web> Order allow,deny Allow from all </Directory> </IfModule>
三、重啟apache,輸入http://localhost/web/index.php 就可以訪問你的專案檔案了
然後,虛擬主機
一、先開啟虛擬主機設定,也就是開啟這個功能
同樣在httpd.conf檔案中,找到:Include conf/extra/httpd-vhosts.conf 將前面的#去掉
二、找到httpd-vhosts.conf檔案,新增一個virtualhost
<VirtualHost *:80> DocumentRoot "c:/Program Files (x86)/my/apache2.2.25/htdocs" ServerName virtual.com DirectoryIndex index.html <Directory "c:/Program Files (x86)/my/apache2.2.25/htdocs"> Options -Indexes FollowSymLinks AllowOverride None Order allow,deny Allow from all </Directory> </VirtualHost>
三、在windows/system/driver/etc/hosts檔案中新增主機對映
127.0.0.1 virtual.com
四、重啟apache,然後訪問該域名就可以看到專案了