配置多個Apache目錄

本人經測試成功,不懂的能夠留言

 通常咱們在測試的時候,或者在開發的時候,都須要在本身電腦,也就是本地配置好php環境一遍開發或者測試,但時候因爲咱們在開發或者測試的過程 中,有可能不單單是一個網站,這時候咱們就須要配置多個站點的,因爲本地沒辦法綁定域名,因此咱們也只能經過IP或者localhost+端口訪問,那麼 如今咱們就來說一下如何在本機實現綁定多個端口多站點的方法;php

 

配置apache的方法這裏就很少說了,能夠參考:web

 

知道配置文件:apache安裝目錄/conf/httpd.confapache

 

找到瀏覽器

# Virtual hosts

#Include conf/extra/httpd-vhosts.conf

去掉#服務器

以下:post

# Virtual hosts

Include conf/extra/httpd-vhosts.conf

 

去掉#是爲了加載擴展配置測試

找到apache安裝目錄/conf/extra/httpd-vhosts.conf網站

 

咱們就開始在這個文件裏面配置多端口多站點了。spa

好比咱們添加一個81端口的站點code

找到

NameVirtualHost *:80

Listen 80

在下面添加一個81端口

Listen 81

 

而後在找到

<VirtualHost *:80>

    ServerAdmin webmaster@dummy-host.example.com

    DocumentRoot "c:/Apache24/docs/dummy-host.example.com"

    ServerName dummy-host.example.com

    ServerAlias www.dummy-host.example.com

    ErrorLog "logs/dummy-host.example.com-error.log"

    CustomLog "logs/dummy-host.example.com-access.log" common

</VirtualHost>

 

這裏的數據是否是不少啊,咱們不須要那麼多,咱們只須要服務器名,和項目目錄就行----------------virtuahost 能夠直接寫在 http.conf 裏

 

咱們改爲

<VirtualHost *:80>

    DocumentRoot "D:/www" 

    ServerName 127.0.0.1


</VirtualHost>

 

 

若是想要經過81端口訪問,咱們則添加下面的端口

 

<VirtualHost *:81>

    DocumentRoot "D:/www/test" 

    ServerName 127.0.0.1:81

</VirtualHost>

  

 

如今咱們已經成功配置好多端口多站點了,咱們重啓一下apache,再來測試一下。

 

下面咱們在瀏覽器輸入

localhost

則默認訪問的是D:/www項目

 

輸入localhost:8080

訪問的則是D:/www/test項目

相關文章
相關標籤/搜索