2012. 4. 2. 15:46ㆍ99. 정리전 - IT/13. Apache 관련
개요 |
톰켓이하의 여러 컨테이너와, 포트가 상이한 별개의 서버를 모두 80포트를 이용하여 서비스 |
목적 |
Tomcat에는 여러가지 컨테이너가 존재하며 이를 2차 도메인으로 구분할 것이며, 동일 컴퓨터 내에 운영되고 있는 tomcat도 apache도 아닌 별도의 웹서버(8085포트)로 서비스되는 것을 apache의 virtualhost와 proxy를 이용하여 80포트로 접근 가능하게 한다. |
proxy역할 |
8085 포트로만 접근가능한 별개의 서버를 apache를 통해 80으로 접근 할 수 있게 포워딩 시켜줌 |
1. Apache2.2 환경설정 (mod_jk.so를 apache의 modules 폴더에 넣는다)
httpd.conf 추가수정
... 생략 ...
#Listen 12.34.56.78:80
Listen 80
... 생략 ...
# Example:
... 생략 ...
LoadModule proxy_module modules/mod_proxy.so
#LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
#LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule proxy_connect_module modules/mod_proxy_connect.so
#LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
LoadModule proxy_http_module modules/mod_proxy_http.so
#LoadModule proxy_scgi_module modules/mod_proxy_scgi.so
... 생략 ...
LoadModule jk_module modules/mod_jk.so
# Configure mod_jk
JkLogFile logs/jk.log
JkLogLevel info
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
JkRequestLogFormat "%w %V %T"
# JkWorkerProperty
JkWorkerProperty worker.list=ajp13
JkWorkerProperty worker.ajp13.type=ajp13
JkWorkerProperty worker.ajp13.host=localhost
JkWorkerProperty worker.ajp13.port=8009
AddDefaultCharset EUC-KR
...생략...
#
# This should be changed to whatever you set DocumentRoot to.
# 이하는 웹컨테이너에서 ajp 모쥴을 통하지 않고 아파치 딴에서 그림을 처리하는데 그림이 안나올때
#
<Directory "C:/A.com/ROOT">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
<Directory "C:/chat.com/ROOT">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
<Directory "C:/blog.com/ROOT">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
... 생략 ...
<IfModule !mpm_netware_module>
<IfModule !mpm_winnt_module>
... 생략 ...
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
httpd-vhosts.conf 추가수정
#
# Virtual Hosts
#
# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at
# <URL:http://httpd.apache.org/docs/2.2/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.
#
# Use name-based virtual hosting.
#
NameVirtualHost *:80
#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#
<VirtualHost *:80>
ServerAdmin a@A.com
DocumentRoot "C:/A.com/ROOT"
ServerName A.com
ServerAlias www.A.com
ErrorLog "logs/www.A.com-error.log"
CustomLog "logs/www.A.com-access.log" common
JkMount /*.do ajp13
JkMount /*.jsp ajp13
JkMount /servlet/* ajp13
JkUnMount /*.html ajp13
JkUnMount /*.gif ajp13
JkUnMount /*.jpg ajp13
JkUnMount /*.jpeg ajp13
JkUnMount /*.bmp ajp13
JkUnMount /*.png ajp13
JkUnMount /*.php ajp13
JkUnMount /*.htm ajp13
JkUnMount /*.html ajp13
</VirtualHost>
<VirtualHost *:80>
ServerAdmin chat@A.com
DocumentRoot "C:/chat.A.com/ROOT"
ServerName chat.A.com
ErrorLog "logs/chat.A.com-error.log"
CustomLog "logs/chat.A.com-access.log" common
JkMount /*.do ajp13
JkMount /*.jsp ajp13
JkMount /servlet/* ajp13
JkUnMount /*.html ajp13
JkUnMount /*.gif ajp13
JkUnMount /*.jpg ajp13
JkUnMount /*.jpeg ajp13
JkUnMount /*.bmp ajp13
JkUnMount /*.png ajp13
JkUnMount /*.php ajp13
JkUnMount /*.htm ajp13
JkUnMount /*.html ajp13
</VirtualHost>
<VirtualHost *:80>
ServerAdmin blog@A.com
DocumentRoot "C:/blog.A.com/ROOT"
ServerName blog.A.com
ErrorLog "logs/blog.A.com-error.log"
CustomLog "logs/blog.A.com-access.log" common
JkMount /*.do ajp13
JkMount /*.jsp ajp13
JkMount /servlet/* ajp13
JkUnMount /*.html ajp13
JkUnMount /*.gif ajp13
JkUnMount /*.jpg ajp13
JkUnMount /*.jpeg ajp13
JkUnMount /*.bmp ajp13
JkUnMount /*.png ajp13
JkUnMount /*.php ajp13
JkUnMount /*.htm ajp13
JkUnMount /*.html ajp13
</VirtualHost>
<VirtualHost *:80>
ServerAdmin music@A.com
ServerName music.A.com
ErrorLog "logs/music.A.com-error.log"
CustomLog "logs/music.A.com-access.log" common
ProxyPass / http://localhost:8085/
ProxyPassReverse / http://localhost:8085/
</VirtualHost>
2. Tomcat7 환경설정
server.xml 추가수정
<?xml version='1.0' encoding='utf-8'?>
... 생략 ...
</Host>
<!-- Add Setting DnsEver.com -->
<Host name="A.com" appBase="C:/A.com"
unpackWARs="true" autoDeploy="true">
</Host>
<Host name="www.A.com" appBase="C:/A.com"
unpackWARs="true" autoDeploy="true">
</Host>
<Host name="chat.A.com" appBase="C:/cjat.A.com"
unpackWARs="true" autoDeploy="true">
</Host>
<Host name="blog.A.com" appBase="C:/blog.A.com"
unpackWARs="true" autoDeploy="true">
</Host>
</Engine>
</Service>
</Server>
마지막으로 톰켓의 카탈리나에 컨텍스트 위치를 파일 단위로 설정
C:\Program Files\Apache Software Foundation\Tomcat 7.0\conf\Catalina\A.com\ROOT.xml
<?xml version="1.0" encoding="utf-8"?>
<Context crossContext="true" docBase="D:/WWW/A.com/ROOT" path="/" reloadable="true">
</Context>
3. hosts 설정 (로컬 테스트를 위한)
127.0.0.1 A.com
127.0.0.1 www.A.com
127.0.0.1 chat.A.com
127.0.0.1 blog.A.com
127.0.0.1 music.A.com