아파치 가상호스트로 두 개 사이트 운영하기
서버는 한대요~~ 가지고 있는 도메인은 두개라~~면?
한 대에서 서로 다른 사이트 두 개를 운영하는 방법이 있다.
이름하야, '아파치 가상호스트'!!!
아파치가 현재 하나 도메인 주소, 예를 들어 aaa.com 으로 접속되도록 설정이 되어있다고 하면, 그 기본 설정 파일이 /etc/apache2/sites-available/000-default.conf 이다.
만약, bbb.com 도 같은 서버에서 돌리고 싶으면 어떻게 하면 될까나...?
어디 도메인 파는 사이트에서 bbb.com 을 사고, 네임서버에서 bbb.com 이 현재 서버의 아이피를 가리키도록 설정부터 해야겠지..이건 되어 있다고 가정을 하고 시작~!
우선 bbb.com 을 위한 파일들을 저장할 공간부터 마련을 해야한다.
편하게 따로 계정을 만들어서 사용하는 것이 편할거 같다.
그래서,
# adduser bbb
해서 계정만들고, /home/bbb/ 아래에 www 이라고 디렉토리 만들어주고 그 안에 접속 테스트용으로 index.php 나 index.htm 를 만들어 주자.
이제 아파치 가상서버 설정이다.
/etc/apache2/sites-available/000-default.conf.ori 를 bbb.com.conf 로 복사를 하자.
000-default.conf.ori 는 아파치 설치 후에 아무런 수정을 하지 않은 기본 설정파일, 000-default.conf 를 백업해 놓은 파일이다. 이렇게 가상호스트 설정을 할 때 사용하려고 처음에 백업을 해 놓았다.
아파치 예전 버전에서는 bbb.com 정도로 파일 이름을 정해도 괜찮았는데, 2.4. 버전에서는 a2ensite 가 오류를 뱉더라. 뒤에 꼭 conf 라고 붙여줘야한다.
준비된 bbb.com.conf 를 편집기로 열어서 수정을 해 주자. 빨간 색으로 표시한 부분만 알맞게 수정해주면 되겠다.
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
ServerName bbb.com
ServerAlias www.bbb.com
ServerAdmin admin@bbb.com
DocumentRoot /home/bbb/www
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog /home/bbb/logs/error.log
CustomLog /home/bbb/logs/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
/etc/apache2/sites-available/bbb.com.conf 가 생겼다. 우린 이 파일을 /etc/apache2/sites-enabled/ 로 옮겨야한다. 그냥 복사해서 붙여넣는게 아니고... a2ensite 를 이용한다.
$ sudo a2ensite bbb.com
bbb.com.conf 라고 적어도 된다.
/etc/apache2/sites-enabled/ 에 가 보면, bbb.com.conf 가 생겨있는것을 확인할 수 있다. 사실 sites-available 에 있는 bbb.com.conf 로 링크가 걸려있다.
그 다음은, /etc/apach2/apache2.conf 를 수정해주자.
쭉~ 내려가서 아래 비스무리한 내용들이 나오는 부분에서 아래처럼 bbb.com 을 위한 디렉토리, /home/bbb/www/ 을 설정해줘야한다.
아래 내용 중, 빨간 색 부분만 그대로 추가하면 되겠다.
<Directory /home/webmaster/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
<Directory /home/bbb/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
이제 가상호스트 bbb.com 에 대한 설정파일 bbb.com.conf 도 만들어줬고, apache2.conf 에서 가상호스트를 위한 설정도 추가를 해 줬다.
그럼, 아파치를 재시작해주자.
$ sudo service apache2 restart
오케이! 브라우저에서 bbb.com 을 접속하면 /home/bbb/www/ 안에 준비해둔 index.php(html) 가 표시될 것이다.
끝!
'우분투' 카테고리의 다른 글
[우분투 14.04] 화면 캡쳐 (0) | 2015.03.07 |
---|---|
[우분투] 14.04에서 메일 포워딩 설정하기 (0) | 2014.10.31 |
[우분투] 14.04에서 서버에 도메인 네임 추가하기 (0) | 2014.10.28 |
[우분투] 14.04에서 bind9 이용해 DNS 설치하기 (2) | 2014.10.28 |
[우분투] 14.04에서 apache2 루트 디렉토리 변경하기 (2) | 2014.10.28 |
댓글