-
본문으로 바로가기

우분투 16.04 또는 14.04 LTS 버전에서 apache2 버추얼 호스팅 하는 방법을 알려드리겠습니다.


우분투 apache2 버추얼 호스팅 하는 방법

1. apache2 설치

2. apache2 기본 설정 확인

3. 버추얼 호스팅 정보 확인 및 추가

4. apache sites available > enable

5. 아파치 재시작


1. apache2 설치

coco@local:~$ sudo apt install apache2

 

2. apache2 기본 설정 확인

(포트 80번 말고 다른거 쓴다면, 다른걸로 변경하거나 추가)

coco@local:~$ sudo nano /etc/apache2/ports.conf

 

(버추얼 호스팅 하고자 할 경우 apache2.conf 수정할 라인 약 153이 있다.

coco@local:~$ sudo nano /etc/apache2/apache2.conf
# Include list of ports to listen on

Include ports.conf



# Sets the default security model of the Apache2 HTTPD server. It does

# not allow access to the root filesystem outside of /usr/share and /var/www.

# The former is used by web applications packaged in Debian,

# the latter may be used for local directories served by the web server. If

# your system is serving content from a sub-directory in /srv you must allow

# access here, or in any related virtual host.


# 아래 Directory / 부분을 모두 주석 처리 한다.


#<Directory />

#       Options FollowSymLinks

#       AllowOverride None

#       Require all denied

#</Directory>


<Directory /usr/share>

        AllowOverride None

        Require all granted

</Directory>

 

3. 버추얼 호스팅 정보 확인 및 추가

(기본 호스팅 정보)

sudo nano /etc/apache2/sites-available/000-default.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 kagok.co.kr


        ServerAlias www.kagok.co.kr


        ServerAdmin webmaster@localhost

        DocumentRoot /var/www/html

.....
</VirtualHost>

 

(추가 호스팅 정보)

sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/001-kagok.co.kr.conf 

sudo nano /etc/apache2/sites-available/001-kagok.co.kr.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 kagok.co.kr


        ServerAlias mz.kagok.co.kr

        ServerAdmin 7979et@naver.com

        DocumentRoot /var/www/mz



.....
</VirtualHost>

 

4. apache sites available > enable

cd /etc/apache2/site-available

sudo a2ensite *

 

5. 아파치 재시작

sudo service apache2 restart

 

참고자료

    apache 설정 관련 참고 사이트 : http://www.fun25.co.kr/blog/ubuntu-14-04-apache-virtual-host

    DNS 설정: http://html5around.com/wordpress/tutorials/ubuntu-bind9-local-dns-setup/


이상입니다.

퍼가기 하실때는 출처 꼭 같이 남겨주시면 감사하겠습니다.


출처: 코키티비, http://cocatv.tistory.com/133

반응형