가상 호스팅 (Virtual Hosting)은 하나의 서버(또는 서버 풀)에 여러개의 도메인 이름을 호스팅하는 방식
서버는 메모리, 프로세서 사이클 등 자신의 자원을 공유할 수 있고, 동일한 호스트명을 사용하기 위해 제공되는 모든 서비스가 필요하지 않음
일반적인 웹서버는 왼쪽 표와 같이 도메인에 각각의 IP가 할당되는데, 가상 호스팅을 사용하면 오른쪽과 같이 도메인은 다르지만 하나의 서버로 사용할 수 있다.
| 도메인 | IP |
|---|---|
| sooyeon1.com | 111.111.111.111 |
| sooyeon2.com | 222.222.222.222 |
| 도메인 | IP |
|---|---|
| sooyeon1.com | 111.111.111.111 |
| sooyeon2.com | 111.111.111.111 |
목표
실습 환경
v hosting 설정을 위해 /etc/httpd/conf.d/vhost.conf 생성 & 편집
vi /etc/httpd/conf.d/vhost.conf
<VirtualHost *:80>
ServerAdmin webmaster@test1.com
ServerName test1.com
ServerAlias sooyeon1.test.com
DocumentRoot /var/www/html/sooyeon1.d/
DirectoryIndex index.html
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster@test2.com
ServerName test2.com
ServerAlias sooyeon2.test2.com
DocumentRoot /var/www/html/sooyeon2.d/
DirectoryIndex index.html
</VirtualHost>
vhost.conf 파일 접근 권한 설정
sudo chmod a+x vhost.conf
구성파일 적용
apachectl configtest
apachectl graceful
웹서버 접속할 PC의 호스트 파일 변경
Window의 호스트 파일 접근하기
메모장 > 관리자 권한으로 열기
Windows>System32>drivers>etc>hosts


- 호스트 파일에 4줄 추가
```bash
# 파일 내용 작성 후 저장
192.168.1.114 test1.com
192.168.1.114 sooyeon1.test1.com
192.168.1.114 test2.com
192.168.1.114 sooyeon2.test2.com
```
PC에서 리눅스로 ping 테스트 하기
ping 192.168.1.114

sooyeon1의 index.html과 sooyeon2의 index.html 작성
vi /var/www/html/sooyeon1.d/index.html
vi /var/www/html/sooyeon2.d/index.html
DocumentRoot 디렉토리 접근권한 설정
chmod a+x /var/www/html/sooyeon1.d/ -R
chmod a+x /var/www/html/sooyeon2.d/ -R
PC에서 웹 브라우저 접속 확인

