카테고리 없음
[xampp] 가상 호스트 사용법 (내부망)
chanYongYong
2026. 7. 29. 23:20
1. 내 PC에서만 쓸 때: hosts + .test
프로젝트별로 주소를 정함
launcher.test
manage.test.hi
home
(주소에 .com .test .a.b 등 뭐가 들어와서 상관 X)
Windows의 다음 파일에:
C:\Windows\System32\drivers\etc\hosts
아래처럼 등록
127.0.0.1 launcher.test
127.0.0.1 manage.test.hi
127.0.0.1 home
그리고 C:\xampp\apache\conf\extra\httpd-vhosts.conf:
<VirtualHost *:80>
ServerName launcher.test
DocumentRoot "C:/xampp/htdocs/launcher"
<Directory "C:/xampp/htdocs/launcher">
Options -Indexes +FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName manage.test.hi
DocumentRoot "C:/xampp/htdocs/manage"
<Directory "C:/xampp/htdocs/manage">
Options -Indexes +FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName home
DocumentRoot "C:/xampp/htdocs/home"
<Directory "C:/xampp/htdocs/home">
Options -Indexes +FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
이제 이렇게 바로 접속 가능
http://launcher.test
http://manage.test.hi
http://home
2. 내부망의 몇 대만 쓸 때
서버 PC의 내부 IP가 192.168.0.20이라고 가정하면, 접속할 PC들의 hosts 파일에 다음과 같이 입력 후 저장
C:\Windows\System32\drivers\etc\hosts
192.168.0.20 launcher
192.168.0.20 manage
(마찬가지로 주소에 .com .test .a.b 등 뭐가 들어와서 상관 X)
서버의 Apache에는:
<VirtualHost *:80>
ServerName launcher
DocumentRoot "C:/xampp/htdocs/launcher"
<Directory "C:/xampp/htdocs/launcher">
Options -Indexes +FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName manage
DocumentRoot "C:/xampp/htdocs/manage"
<Directory "C:/xampp/htdocs/manage">
Options -Indexes +FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
그러면 내부 PC에서:
http://launcher
http://manage
로 접속.
몇 대까지는 이 방식이 편함
- 1대: 내 PC의 hosts만 수정
- 2~5대: 각 PC의 hosts 수정
- PC가 많거나 IP가 자주 바뀜: 내부 DNS 서버 사용
내부 DNS를 쓰면 접속 PC마다 hosts 파일을 수정할 필요 없이 DNS 한 곳에만 등록하면 됨.
3. 기본 가상 호스트를 차단용으로 만들기
Apache는 입력된 주소가 어떤 ServerName과도 일치하지 않으면 첫 번째 가상 호스트를 기본 사이트로 사용.
따라서 첫 번째에 실제 사이트가 아닌 차단용 가상 호스트를 두면, 타 사이트와 헷갈리지 않음
!꼭 맨 첫번째로 default가 와야 함
<VirtualHost *:80>
ServerName default.invalid
DocumentRoot "C:/xampp/htdocs/_blocked"
<Directory "C:/xampp/htdocs/_blocked">
Require all denied
</Directory>
</VirtualHost>