利用Apache配置本地 自定義域名

一喵嗚發表於2015-06-20

第一步:配置 httpd.conf

    開啟 虛擬主機 配置模組 去掉 " Include conf/extra/httpd-vhosts.conf "  前面的" # "

# Virtual hosts Includeconf/extra/httpd-vhosts.conf

 

第二步:配置 httpd-vhosts.conf

    開始 將自定義的本地域名 與 web目錄 關聯  這裡自定義了 

               www.royal.org  

               www.superapp.com  

               www.api.com 

這三個本地域名 (當然這三個域名 是不能遠端訪問的 什麼原因 你懂的!)

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
NameVirtualHost *:80
 
<VirtualHost *:80>
    ServerName *
    DocumentRoot D:\web\apache2.2\Apache2\htdocs
</VirtualHost>
 
<VirtualHost *:80>
     ServerName www.royal.org
    DocumentRoot "D:\web\apache2.2\Apache2\htdocs\Royal"
    <Directory "D:\web\apache2.2\Apache2\htdocs\Royal">
        Options Indexes FollowSymLinks
        AllowOverride None
        Order allow,deny
        Allow from all
    </Directory> 
</VirtualHost>
 
 
<VirtualHost *:80>
    ServerName www.superapp.com
    DocumentRoot "D:\web\apache2.2\Apache2\htdocs\scApp7"
    <Directory "D:\web\apache2.2\Apache2\htdocs\scApp7">
        Options Indexes FollowSymLinks
        AllowOverride None
        Order allow,deny
        Allow from all
    </Directory> 
</VirtualHost>
 
 
<VirtualHost *:80>
    ServerName www.api.com
    DocumentRoot "D:\web\apache2.2\Apache2\htdocs\taobaoApi"
    <Directory "D:\web\apache2.2\Apache2\htdocs\taobaoApi">
        Options Indexes FollowSymLinks
        AllowOverride None
        Order allow,deny
        Allow from all
    </Directory> 
</VirtualHost>

第三步: 配置windows hosts檔案

    開啟 C:\WINDOWS\system32\drivers\etc\hosts 檔案 

   (hosts檔案其實 就是 internet 的雛形 最早的internet 是 ARPA 用於內部的 主機的域名解析)

1
2
3
127.0.0.1 www.royal.org 
127.0.0.1 www.superapp.com 
127.0.0.1 www.api.com


第四步:沒喲了! 在瀏覽器上 輸入 www.api.com  www.superapp.com  www.royal.com  就會訪問不同的本地web目錄

相關文章