IIS 之 IIS 7及以上多域名或端口綁定同一物理目錄並設置不同默認文檔
阿新 • • 發佈:2017-06-08
clas host doc ebs dex 導致 color 不同 amp
今天在 IIS 7 多端口或域名綁定同一物理目錄,設置不同的默認文檔遇到問題:同一物理目錄的多個站點修改任意一個站點默認文檔都會一起更改。
原因:在同一個物理目錄下只有一個 web.config,並且 IIS7 把默認文檔設置寫在這裏,導致所有域名的默認文檔設置共享。
解決方案:
比如我們把 www.ExampleA.com 和 www.ExampleB.com 兩個域名都指向 E:\WebTest 文件目錄,想把 www.ExampleA.com 的默認文檔設為目錄下的 indexA.html,www.ExampleB.com 的默認文檔設為目錄下的 indexB.html。
1、新建兩個站點,一個叫 WebA(站點名字自定義),指向 E:\WebTest 文件夾,綁定域名 www.ExampleA.com;另一個叫 WebB,指向 E:\WebTest 文件夾,綁定域名www.ExampleB.com。
2、進入%windir%\system32\inetsrv\config目錄(%windir%即windows的安裝目錄,比如c:\windows)。
3、找到 applicationHost.config 文件,用文本編輯器打開。
4、在最後 configuration 節中加入如下語句
<location path="WebA"><system.webServer> <defaultDocument enabled="true"> <files> <clear/> <add value="indexA.html"/> </files> </defaultDocument> </system.webServer> </location> <location path="WebB"> <system.webServer> <defaultDocument enabled="true"> <files> <clear/> <add value="indexB.html"/> </files> </defaultDocument> </system.webServer> </location>
5、註意要刪除物理目錄下 web.config 文件中關於默認文檔的設置。
IIS 之 IIS 7及以上多域名或端口綁定同一物理目錄並設置不同默認文檔