Programming/Linux

Apache VirtualHost (아파치 가상호스트 설정)

▒◈§№▩ 2020. 7. 24. 16:52

리눅스 아파치 가상호스트 설정에 대해 알아보도록 하겠습니다. 보통은 httpd.conf 에 호스트 설정하기보다는 vhost.conf 에 여러 도메인을 한 번에 설정을 할 수 있어서 vituralhost에 설정하는 법을 알아보도록 하겠습니다.

 

Apache VirtualHost 설정방법

 

설정전 아파치 버전확인

[root@localhost html]# httpd -v
Server version: Apache/2.4.6 (CentOS)
Server built:   Apr  2 2020 13:13:23

 

1. httpd.conf 파일을 열어줍니다.

[root@localhost html]# vi /etc/httpd/conf/httpd.conf

 

2. 기존에 SverName 은 아래와 같이 주석처리함

#ServerName www.test.com:80

 

3. 그리고 맨아래줄에 아래와 같이 추가 후 저장해 줍니다.

include /etc/httpd/conf/vhost.conf
<Directory "/home">
AllowOverride None
Require all granted
</Directory>

 

4. vhost.conf 파일 생성 후 저장

vi /etc/httpd/conf/vhost.conf

################## test.com Start ##################
<VirtualHost *:80>
        DocumentRoot /home/html
        ServerName test.co.kr
        ServerAlias www.test.co.kr
</VirtualHost>
################## test.com End ##################

 

5. 이후 아래와 같은 순서로 /home/html 폴더를 만들고 index.html 파일 생성해서 간단히 html 코드 넣은 후 저장해 줍니다. 그러고 나서 아파치 재시작해주면 되겠습니다.

mkdir /home/html
cd /home/html/
vi index.html

systemctl restart httpd
ps -ef | grep httpd