아파치 웹 서버 연동

쓰리래빗츠 북과 웹 서버를 연동하려면 아파치 톰캣 커넥터를 사용합니다. 쓰리래빗츠 북이 아파치 톰캣을 이용하기 때문입니다.

윈도우에서 쓰리래빗츠 북과 아파치 웹 서버를 연동한다면 윈도우에서 쓰리래빗츠 북과 아파치 HTTP 서버 설정을 참고합니다.

mod_jk 설치

연동을 위해 mod_jk를 설치해야 합니다. 아파치 톰캣 커넥터 페이지에서 도움이 되는 내용을 찾을 수 있습니다.

아파치 톰캣 커넉터는 1.2.40 버전을 예로 듭니다.

리눅스에 설치

1

1 sources 링크를 이용해서 소스를 받습니다.

서버가 인터넷에 연결되어 있다면 다음과 같이 쉽게 받을 수 있습니다.

wget http://www.apache.org/dist/tomcat/tomcat-connectors/jk/tomcat-connectors-1.2.40-src.tar.gz

2

컴파일하여 설치합니다.

tar xvzf tomcat-connectors-1.2.40-src.tar.gz
cd tomcat-connectors-1.2.40-src/native
./configure --with-apxs=/app/httpd-2.2.27/bin/apxs1
make
make install

Advanced Packaging Tool일명 apt-get 을 지원하면 다음 명령어로 간단하게 설치합니다. 다른 환경에서 설치 방법은 공식 페이지를 참고하세요.

sudo apt-get install libapache2-mod-jk

윈도우에 설치

1

아파치 HTTP 서버에 mod_jk.so 파일 추가

  1. 다음 사이트로 이동합니다. 아파치가 윈도우용 바이너리 파일을 직접 제공하지는 않습니다.

  2. 웹 브라우저에서 Ctrl + F 단축키 누른 후에 jk로 검색합니다.

  3. zip 파일을 내려받습니다.

  1. 압축을 푼 후 mod_jk.so 파일을 APACHE_HOME\modules 디렉터리에 복사합니다.

mod_jk 설정

httpd.conf을 이용

아파치 웹 서버를 httpd.conf 이용하여 관리할 때 사용하는 방법입니다.

XAMP에서 기본으로 사용하는 방법입니다. <XAMP 설치경로\apache\conf>에 httpd.conf 파일이 있습니다.

httpd.conf 의 마지막에 다음 내용을 넣습니다. XAMP를 이용한 예제입니다. 파일의 위치는 사용하고 있는 환경에 맞게 고쳐 씁니다.

# Load mod_jk module
LoadModule jk_module modules/mod_jk.so
# Where to find workers.properties
JkWorkersFile conf/workers.properties
# Where to put jk shared memory
JkShmFile     logs/mod_jk.shm
# Where to put jk logs
JkLogFile     logs/mod_jk.log
# Set the jk log level [debug/error/info]
JkLogLevel    info
# Select the timestamp log format
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "

자세한 내용은 공식 사이트 문서를 참고합니다.

아파치 웹 서버가 설치된 경로를 기준으로 상대 경로를 이용합니다.

mods-enable 디렉토리를 이용해서 활성화

아파치 웹 서버의 설정에 mods-enable을 사용할 때 이용하는 방법입니다.

우분투 서버에 기본으로 설치된 아파치 웹 서버에서 사용하는 방법입니다.

1

아파치 웹 서버 mods-enable 디렉터리에 설정 파일들을 만듭니다.

예시에 사용된 파일은 여기에서 받습니다. 예시의 내용을 실제 환경에 맞게 수정합니다. 자세한 내용은 공식 사이트 문서를 참고합니다.

2

jk.conf 내용을 입력합니다.

JkWorkersFile /etc/apache2/mods-available/workers.properties
JkShmFile /var/log/apache2/mod_jk.shm
JkLogFile /var/log/apache2/mod_jk.log
JkLogLevel info
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
JkRequestLogFormat "%w %V %T"

3

jk.load 내용을 입력합니다.

LoadModule jk_module /usr/lib/apache2/modules/mod_jk.so

workers.properties 만들기

#으로 시작하는 문장들은 설명을 위한 주석입니다. 이해를 돕기 위해 지우지 않았습니다.

리눅스에서는 슬래시 문자, 윈도우에서는 백슬래시 문자 사용하는 것을 주의하세요.

리눅스에서 사용하는 파일

# workers.properties -
#
# This file is a simplified version of the workers.properties supplied
# with the upstream sources. The jni inprocess worker (not build in the
# debian package) section and the ajp12 (deprecated) section are removed.
#
# As a general note, the characters $( and ) are used internally to define
# macros. Do not use them in your own configuration!!!
#
# Whenever you see a set of lines such as:
# x=value
# y=$(x)\something
#
# the final value for y will be value\something
#
# Normaly all you will need to do is un-comment and modify the first three
# properties, i.e. workers.tomcat_home, workers.java_home and ps.
# Most of the configuration is derived from these.
#
# When you are done updating workers.tomcat_home, workers.java_home and ps
# you should have 3 workers configured:
#
# - An ajp13 worker that connects to localhost:8009
# - A load balancer worker
#
#

# OPTIONS ( very important for jni mode )

#
# workers.tomcat_home should point to the location where you
# installed tomcat. This is where you have your conf, webapps and lib
# directories.
#
workers.tomcat_home=/home/rabbitz/app-1-0/tomcat

#
# workers.java_home should point to your Java installation. Normally
# you should have a bin and lib directories beneath it.
#
workers.java_home=/usr/java/jdk1.6.0_35

#
# You should configure your environment slash... ps=\ on NT and / on UNIX
# and maybe something different elsewhere.
#
ps=/

#
#------ ADVANCED MODE ------------------------------------------------
#---------------------------------------------------------------------
#

#
#------ worker list ------------------------------------------
#---------------------------------------------------------------------
#
#
# The workers that your plugins should create and work with
#
worker.list=ajp13_worker

#
#------ ajp13_worker WORKER DEFINITION ------------------------------
#---------------------------------------------------------------------
#

#
# Defining a worker named ajp13_worker and of type ajp13
# Note that the name and the type do not have to match.
#
worker.ajp13_worker.port=8009
worker.ajp13_worker.host=localhost
worker.ajp13_worker.type=ajp13
#
# Specifies the load balance factor when used with
# a load balancing worker.
# Note:
#  ----> lbfactor must be > 0
#  ----> Low lbfactor means less work done by the worker.
worker.ajp13_worker.lbfactor=1

#
# Specify the size of the open connection cache.
#worker.ajp13_worker.cachesize

#
#------ DEFAULT LOAD BALANCER WORKER DEFINITION ----------------------
#---------------------------------------------------------------------
#

#
# The loadbalancer (type lb) workers perform wighted round-robin
# load balancing with sticky sessions.
# Note:
#  ----> If a worker dies, the load balancer will check its state
#        once in a while. Until then all work is redirected to peer
#        workers.
worker.loadbalancer.type=lb
worker.loadbalancer.balance_workers=ajp13_worker

다음 사항을 주의하여 만듭니다.

workers.tomcat_home=/home/rabbitz/app-1-0/tomcat

설치된 경로 아래의 tomcat 디렉토리를 넣습니다.

workers.java_home=/usr/java/jdk1.6.0_35

JDK가 설치된 경로를 넣습니다.

ps=/

리눅스는 슬래시를 사용합니다.

'ajp13_worker'

아파치 설정에서 사용합니다.

윈도우에서 사용하는 파일

# workers.properties -
#
# This file is a simplified version of the workers.properties supplied
# with the upstream sources. The jni inprocess worker (not build in the
# debian package) section and the ajp12 (deprecated) section are removed.
#
# As a general note, the characters $( and ) are used internally to define
# macros. Do not use them in your own configuration!!!
#
# Whenever you see a set of lines such as:
# x=value
# y=$(x)\something
#
# the final value for y will be value\something
#
# Normaly all you will need to do is un-comment and modify the first three
# properties, i.e. workers.tomcat_home, workers.java_home and ps.
# Most of the configuration is derived from these.
#
# When you are done updating workers.tomcat_home, workers.java_home and ps
# you should have 3 workers configured:
#
# - An ajp13 worker that connects to localhost:8009
# - A load balancer worker
#
#

# OPTIONS ( very important for jni mode )

#
# workers.tomcat_home should point to the location where you
# installed tomcat. This is where you have your conf, webapps and lib
# directories.
#
workers.tomcat_home=C:\3rabbitz\tomcat

#
# workers.java_home should point to your Java installation. Normally
# you should have a bin and lib directories beneath it.
#
workers.java_home=C:\Program Files\Java\jdk1.7.0_71

#
# You should configure your environment slash... ps=\ on NT and / on UNIX
# and maybe something different elsewhere.
#
ps=\

#
#------ ADVANCED MODE ------------------------------------------------
#---------------------------------------------------------------------
#

#
#------ worker list ------------------------------------------
#---------------------------------------------------------------------
#
#
# The workers that your plugins should create and work with
#
worker.list=ajp13_worker

#
#------ ajp13_worker WORKER DEFINITION ------------------------------
#---------------------------------------------------------------------
#

#
# Defining a worker named ajp13_worker and of type ajp13
# Note that the name and the type do not have to match.
#
worker.ajp13_worker.port=8009
worker.ajp13_worker.host=localhost
worker.ajp13_worker.type=ajp13
#
# Specifies the load balance factor when used with
# a load balancing worker.
# Note:
#  ----> lbfactor must be > 0
#  ----> Low lbfactor means less work done by the worker.
worker.ajp13_worker.lbfactor=1

#
# Specify the size of the open connection cache.
#worker.ajp13_worker.cachesize

#
#------ DEFAULT LOAD BALANCER WORKER DEFINITION ----------------------
#---------------------------------------------------------------------
#

#
# The loadbalancer (type lb) workers perform wighted round-robin
# load balancing with sticky sessions.
# Note:
#  ----> If a worker dies, the load balancer will check its state
#        once in a while. Until then all work is redirected to peer
#        workers.
worker.loadbalancer.type=lb
worker.loadbalancer.balance_workers=ajp13_worker

다음 사항을 주의합니다.

workers.tomcat_home=C:\3rabbitz\tomcat

쓰리래빗츠가 설치된 경로 아래의 tomcat 디렉토리를 넣습니다.

workers.java_home=C:\Program Files\Java\jdk1.7.0_71

JDK가 설치된 경로를 넣습니다.

ps=\

윈도우는 백슬래시를 사용합니다.

ajp13_worker

아파치 설정에서 사용합니다.

아파치 웹 서버 설정

아파치 웹 서버에서 mod_jk 로 요청을 보내도록 다음 예시에서 강조한 내용을 추가합니다. 수정할 파일은 sites-availables 디렉터리의 default 또는 default-ssl 입니다.

ajp13_workerworkers.properties에서 사용된 이름과 같아야 합니다.
<VirtualHost *:80>

-- 생략된 내용이 있습니다. --

<Directory />
  Options FollowSymLinks
  AllowOverride None
</Directory>

JkMount /* ajp13_worker
JkUnMount /resource/* ajp13_worker정적 파일을 웹 서버에서 처리하기 위한 설정입니다.

ErrorLog /var/log/apache2/error.log

#Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel info

-- 생략된 내용이 있습니다. --
</VirtualHost>

만약 서브 도메인을 이용하려면 다음과 같이 설정합니다. 아파치 가상호스트 문서를 참고하세요.

<VirtualHost doc.3rabbitz.com:80>

-- 생략된 내용이 있습니다. --

<Directory />
  Options FollowSymLinks
  AllowOverride None
</Directory>

JkMount /* ajp13_worker
JkUnMount /resource/* ajp13_worker정적 파일을 웹 서버에서 처리하기 위한 설정입니다.

ErrorLog /var/log/apache2/error.log

#Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel info

-- 생략된 내용이 있습니다. --
</VirtualHost>

개인 PC에서 사용하기 위해서는 hosts 파일에 사용할 도메인 정보를 넣어야 합니다. hosts 파일은 <윈도우 설치 경로C:\Windows\System32\Drivers\etc>에 있습니다.

127.0.0.1 doc.3rabbitz.com

XAMP의 경우 가상 호스트를 관리하는 파일은 <XAMP 설치 경로\apache\conf\extra\httpd-vhosts.conf> 입니다.

톰캣 설정

3RABBITZ_HOME은 쓰리래빗츠 북을 설치한 디렉터리를 지칭합니다.

3RABBITZ_HOME/tomcat/conf/server.xml 파일을 열어서 다음과 같이 내용을 바꿉니다.

<Server port="5791" shutdown="SHUTDOWN">

  <Service name="Catalina">

    <Connector port="8009" protocol="AJP/1.3"
               redirectPort="8443" URIEncoding="UTF-8"  />

    <!--
    <Connector port="1975" protocol="HTTP/1.1"
      connectionTimeout="20000" redirectPort="8443" URIEncoding="UTF-8" />
    -->

    <!-- 이하 생략 -->

  </Service>

</Server>

1

AJP/1.3 설정을 위한 Connector의 주석을 풉니다.

work.properties를 설정할 때 8009 포트 번호를 바꿨다면 바뀐 번호를 사용합니다.

2

HTTP/1.1를 위한 Connector를 주석으로 막습니다.

웹 서버를 거치지 않고 1975 포트로 쓰리래빗츠에 접근하는 것도 허용하려면 주석으로 바꾸지 않습니다.

3

쓰리래빗츠를 다시 시작합니다.

변경 사항을 반영하려면 쓰리래빗츠 북를 다시 시작합니다.


  1. ./configure 값은 "아파치 설치 디렉토리/bin/apxs"을 사용합니다.