戻る

hostsの設定

hostsとは

XAMPP内に作成したWEBページにアクセスするとき、「http://localhost/・・・・・・」というようにアクセスします。普通にテスト環境としてXAMPPを利用するときはlocalhostでも問題ありませんが、本番用に公開するときはドメインあるいはサブドメインが必要になります。本番サーバーにアップロードするとき、プログラム内にlocalhostの記述がある場合は本番用のドメイン名に書き換えてやるか、localhostとドメイン名を切り替えるプログラムを特別に作る必要があります。

そのようなとき、「hosts」に、本番で使用したいドメイン名を設定することでXAMPP内のWEBページにアクセスする際に本番用のドメイン名でアクセスすることができます。但し、完成したあとは「hosts」からドメイン名をはずしておかないと自分自身で本番用のサイトにアクセスすることができません。

また、localhostとは、自分自身を表すIPアドレスである127.0.0.1に割り当てられています。127.0.0.1はネットワークアダプタに割り当てられた仮想的なアドレスで、ループバックアドレスといい、127.0.0.1にアクセスすると自分自身に戻ってくるようになっています。

hostsの場所

file:///C:/windows/system32/drivers/etc/hosts

Windows Vista、Windows 7の場合はスタートメニューに登録された「アクセサリ->メモ帳」のショートカットアイコンを右クリックして「管理者として実行(A)」からメモ帳を起動してhostsを読み込んでください。

# Copyright (c) 1993-2009 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

# localhost name resolution is handled within DNS itself.
#	127.0.0.1	   localhost
#	::1			 localhost


#最初から設定されているループバックアドレス
127.0.0.1	localhost

#ループバックアドレスに対してhostsを設定
127.0.0.1	testdomain.jp

#LANで割り当てられたIPアドレスに対してhostsを設定
192.168.0.2	testdomain2.jp
192.168.0.3	testdomain3.jp
192.168.0.4	testdomain4.jp
inserted by FC2 system