Skip to content

Apache2 가상호스트 #
Find similar titles

Structured data

Category
Programming

아파치(Jakarta Apache)2 가상호스트 설정 #

  • 2개 이상의 도메인을 동일 서버에서 제공하고자 하는 경우 아파치 웹 서버 가상호스트 설정방법
  • mode JK를 통한 Apache Tomcat WAS(Web Application Server)서버와 연동 방법

설치 전 설치환경 및 설치파일 다운로드 #

1. 아파치 설치 파일 컴파일

[root@localhost ~]# tar -xzvf httpd-2.2.29.tar.gz
[root@localhost ~]# tar -xzvf httpd-2.2.29.tar.gz
[root@localhost httpd-2.2.29]# ./configure -prefix=/usr/local/apache2
[root@localhost httpd-2.2.29]# make 
[root@localhost httpd-2.2.29]# make install

2. mod_jk 설치

[root@localhost ~]# cd tomcat-connectors-1.2.40-src/native
[root@localhost native]# LDFLAGS=-L/usr/local/apache2/lib CPPFLAGS=-I/usr/local/apache2/include ./configure --with-apxs=/usr/local/apache2/bin/apxs
[root@localhost native]# make
[root@localhost native]# libtool --finish /usr/local/apache2/modules
[root@localhost native]# make install
[root@localhost native]# ls /usr/local/apache2/modules
httpd.exp mod_jk.so

3. mod_proxy, mod_proxy_ajp 설치

[root@localhost httpd-2.2.29]# cd modules/proxy
[root@localhost proxy]# /usr/local/apache2/bin/apxs -i -a -c mod_proxy.c proxy_util.c 
[root@localhost proxy]# /usr/local/apache2/bin/apxs -i -a -c mod_proxy_http.c proxy_util.c
[root@localhost proxy]# /usr/local/apache2/bin/apxs -i -a -c mod_proxy_connect.c proxy_util.c
[root@localhost proxy]# /usr/local/apache2/bin/apxs -i -a -c mod_proxy_ajp.c proxy_util.c ajp_header.c ajp_utils.c ajp_link.c ajp_msg.c
[root@localhost proxy]# cd /usr/local/apache2/modules
[root@localhost modules]# ls
httpd.exp  mod_jk.so  mod_proxy.so  mod_proxy_ajp.so  mod_proxy_connect.so  mod_proxy_http.so

4. Apache 설정파일 변경

LoadModule jk_module modules/mod_jk.so
LoadModule proxy_module       modules/mod_proxy.so
LoadModule proxy_http_module  modules/mod_proxy_http.so
LoadModule proxy_connect_module modules/mod_proxy_connect.so
LoadModule proxy_ajp_module   modules/mod_proxy_ajp.so

# Virtual hosts
Include conf/extra/httpd-vhosts.conf

#JK Connection Configuration
include conf/mod_jk.conf

5. mod_jk 설정파일 편집

1) uriworkermap.properties 편집

[root@localhost ~]# cd /usr/local/apache2/conf
[root@localhost conf]# vi uriworkermap.properties
/*.jsp=ajp13
/*.do=ajp13
/servlet/*=ajp13

2) workers.properties 편집

[root@localhost conf]# vi workers.properties
workers.tomcat_home=/usr/local/tomcat6
workers.java_home=/usr # RPM으로 JDK가 설치된 경우 
ps=/

worker.list=worker1

worker.worker1.port=8009
worker.worker1.host=localhost
worker.worker1.type=ajp13
worker.worker1.lbfactor=1
worker.worker1.socket_timeout=120

worker.loadbalancer.type=lb
worker.loadbalancer.balanced_workers=worker1

worker.inprocess.type=jni
 worker.inprocess.class_path=$(workers.tomcat_home)$(ps)lib$(ps)tomcat.jar
worker.inprocess.cmd_line=start
worker.inprocess.jvm_lib=$(workers.java_home)$(ps)jre$(ps)lib$(ps)
i386$(ps)classic$(ps)libjvm.so

worker.inprocess.stdout=$(workers.tomcat_home)$(ps)logs$(ps)inprocess.stdout
worker.inprocess.stderr=$(workers.tomcat_home)$(ps)logs$(ps)inprocess.stderr

3) mod_jk.conf 편집

[root@localhost conf]# vi mod_jk.conf
<IfModule mod_jk.c>
    JkWorkersFile "/usr/local/apache2/conf/workers.properties"
    JkLogFile "/usr/local/tomcat6/logs/mod_jk.log"
    JkLogLevel info
    JkMountFile "/usr/local/apache2/conf/uriworkermap.properties"

    JkLogStampFormat "[%a %b %d %H:%M:%S %Y]"
    JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
    JkRequestLogFormat "%w %V %T"
</IfModule>

6. 아파치 가상호스트 설정

ProxyRequests On

<VirtualHost *>
    <Proxy *>
        Order deny,allow
        Allow from all
    </Proxy>

    ServerName www.domain1.com

    # 서비스용 아파치 서버가 8011에서 서비스 하는 경우
    RedirectMatch /$ http://localhost:8011/
    ProxyPass / http://localhost:8011/
    ProxyPassReverse / http://localhost:8011/
</VirtualHost>

<VirtualHost *>
    <Proxy *>
        Order deny,allow
        Allow from all
    </Proxy>

    ServerName www.domain2.com

    # domain2 로 들어오는 경우 Tomcat 으로 서비스를 연결하는 경우 
    RedirectMatch /$ http://localhost:8009/
    ProxyPass / ajp://localhost:8009/
    ProxyPassReverse / ajp://localhost:8009/
</VirtualHost>

설정이 완료된 후 톰캣과 아파치 서버를 재가동한 후 웹 브라우저에 각각의 도메인을 입력하고 접속하면 각각의 서비스로 분기된 것을 확인할 수 있다.

0.0.1_20140628_0