2010年12月28日 星期二

【轉貼】利用Windows的Hosts設定來測試網站

【轉貼】利用Windows的Hosts設定來測試網站

因為我接的大多是較為複雜的案子,可能需要同時編寫Server端和Client端的程式,當然功能測試也是非常重要的一環,所以今天我來分享一些測試系統的小技巧。

顧客的網站我大多在我的Lab Server上做測試,為了開發方便所以我所採用的是Windows Server(可以同時開發JSP,ASP.NET,PHP,ColdFusion…),每個客戶的的案子當然就放在Web Server的虛擬伺服器上,要測試的時候很多人可能會有點傷腦經。
其實這個不是問題,只要是MIS都會知道Windows裡面有個hosts的檔案,可以讓使用者自己去調整IP的對應方式,例如你可以在瀏覽器中輸入http://localhost,這其實等同你輸入http://127.0.0.1,為什麼會這樣呢?原因就在於在hosts中有描述localhost的domain name其實是要對應到127.0.0.1這個IP的,所以若你想要將某個domain name對應到自己的測試環境,只要去修改這個設定檔就可以了,而不需要去動到整個網路環境。
 這個檔案的位置在 C:\WINDOWS\system32\drivers\etc\hosts ,找到後用Notepad打開就可以直接編輯了,例如下例,我們將 http://blog.riaproject.com 直接指定到 127.0.0.1,只需要這樣做:
# Copyright (c) 1993-1999 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a ‘#’ symbol.
#
# For example:
#
#      102.54.94.97     rhino.acme.com          # source server
#       38.25.63.10     x.acme.com              # x client host
127.0.0.1       localhost
127.0.0.1       blog.riaproject.com

沒有留言:

張貼留言