2009년 3월 5일 목요일

JSP: About Resin.conf

Resin.conf는 크게 아래와 같은 구조를 갖는다.
일반적으로 resin.conf의 Depth는 아래의 예를 따른다.

<caucho.com>
<http-server>
<host id=''>
<web-app id='/'>
<servlet-mapping url-pattern='/test' .../>
</web-app>
</host>
</http-server>
</caucho.com>

대부분의 중요한 설정은 web-app에 속해 있다.
Server는 다수의 host element를 포함하며 각 host 는 다수의 web-app 들을 포함할 수 있다.
각 host 는 가상host를 설정하고 각 web-app 는 application을 설정한다.

<caucho.com>
<http-server>
<host id='gryffindor.caucho.com' app-dir='gryffindor'>
<web-app id='/'>
<servlet-mapping .../>
...
</web-app>

<web-app id='/test' app-dir='/usr/local/test'>
...
</web-app>
</host>

<host id='slytherin.caucho.com' app-dir='slytherin'>
...
</host>

...
</http-server>
</caucho.com>

Simple configurations host 와web-app tag의 생략을 허용한다. 만약 host 와 web-app를
생략한다면 default host 와 default application를 사용하게 되며 http-server element 의 모든 web-app에 동일한 설정을 적용하게 된다.

<caucho.com>
<http-server app-dir='/usr/local/web'>
<servlet-mapping .../>
...
</http-server>
</caucho.com>

1. <caucho.com>의 하위 엘리먼트

<log id='/log' href='stderr:' timestamp='[%Y-%m-%d %H:%M:%S.%s]'/>
로깅을 위한 설정부분이며 id별로 각기 다른 로그를 지정할 수 있다.
rollover-count : 몇번의 로그변경을 보관할지 설정
rollover-period : 로그변경 주기 설정
ex> rollover-period=’1d’라고 설정하면 stderr.log.20050301의 형태로 매일 로그가 쌓이게 된다

<security-provider id='com.sun.net.ssl.internal.ssl.Provider'/>
JSSE(Java Secure Socket Extension)를 사용하기 위한 security-provider설정 부분으로 Caucho에서는 설정의 어려움과 성능 저하를 이유로 OpenSSL이나 SSL for Apache/IIS를 사용할 것을 권고하고 있으므로 특별한 경우가 아니면 사용하지 않는 것이 좋다.

<java compiler="internal" compiler-args=""/>
Compiler옵션으로 internal이 default이며 javac나 jikes등의 외부 컴파일러를 지정할 수 있다.

<resource-ref>
<res-ref-name>jdbc/test</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<init-param driver-name="com.caucho.jdbc.mysql.Driver"/>
<init-param url="jdbc:mysql_caucho://localhost:3306/test"/>
<init-param user=""/><init-param password=""/>
<init-param max-connections="20"/>
<init-param max-idle-time="30"/>
</resource-ref>
JNDI를 사용한 resin connection pool을 사용할 경우 설정이며 res-ref-name 은 pool name을 의미하며 그 외의 설정은 tag와 property를 참조한다.

<jsp precompile='true' static-encoding='true' recompile-on-error='true'/>
jsp페이지를 precompile하도록 지정하여 다음 접속시 바로 이용할 수 있도록 한다.
Recompile-on-error를 지정하여 jsp페이지를 compile시 java.lang.error가 발생하면 자동으로 recompile되도록 한다. Shift-JIS와 같은 인코딩을 이용해서 writing하고 UTF-8으로 printing하려면 static-encoding을 비활성시킨다.


2. <http-server>의 하위 엘리먼트

<doc-dir>doc</doc-dir>
Server의 root file이 위치한 디렉토리를 지정한다.
Apache : /usr/local/apache/htdocs, IIS : d:\inetpub\wwwroot로 변경하여 사용할 수 있다.

<http port='8080'/>
Resin을 Standalone으로 구동할 경우 사용할 http port를 지정한다.

<srun host='127.0.0.1' port='6802'/>
Load balancing을 위해 Apache나 IIS에 plugin으로 Resin을 사용할 경우의 srun port를 지정한다.

<http port=8443>
<ssl>true</ssl>
<key-store-type>pkcs12</key-store-type>
<key-store-file>keys/server_cert.p12</key-store-file>
<key-store-password>changeit</key-store-password>
</http>
SSL을 사용하는 경우 위와 같은 설정을 하며 아래의 내용을 포함한다.
key-store-type : key store의 종류(ex:비밀키, 공개키 방식)
key-store-file : key store 파일의 위치
key-strore-password : key store파일 access password

<user-name>resin</user-name>
<group-name>resin</group-name>
만약 Unix에서 bin/httpd.sh을 root로 구동할 경우 web server user를 위해 특정 Group name과 User name을 제공해야 한다. RedHat 9.0이후 Linux에서는 bin/resin을 사용해야 한다.

<class-update-interval>2s</class-update-interval>
사용자에 의해 class파일이 update됬는지 여부를 검사하는 주기이다. 이 주기에 따라 resin이 검사하므로 해당 주기를 줄이면 변경즉시 반영되므로 개발시 유용하나 서버에 부하가 가중되므로 운영시는 낮춰주는 것이 좋다.

<servlet-classloader-hack>false</servlet-classloader-hack>
True로 설정하면 Servlet spec 에 따른 classloader를 사용하고 false이면 JDK spec에 따른 classloader를 사용한다.

<error-page exception='connection' location='/my-error-page.html'/>Apache나 IIS를 이용할 시에 srun connection 실패시 표시할 error 페이지를 지정한다.

<caucho-status>true</caucho-status>
Caucho-status를 표시한다.

<thread-max>150</thread-max>
서버당 최대 thread갯수

<thread-keepalive id='100'/>
Keepalive할 trhead수.

<request-timeout id='65s'/>
Socket keepalive 시간. SSL을 사용하지 않는다면 짧게 하는 것이 성능에 좋다.

<accept-buffer-size id='256'/>
Accept buffer상의 socket 수

<thread-min id='5'/>
Socket에서 대기될 때 요청되는 최대 thread 수

<ping sleep-time='1m' retry-count='3' retry-time='1s'>
<url>http://localhost:8080/ping/ping.jsp</url>
</ping>
web server 상태를 확인하기 위해 ping test를 하기 위한 설정이다.
test결과 failuer가 발생하면 resin은 서버를 restart한다.
해당 test를 위한 thread가 JDK와 같기 때문에 해당 Thread의 deadlocks이나 Database connection 증가로 인한 memory leak같은 경우는 catch할 수 없다.

<ignore-client-disconnect>true</ignore-client-disconnect>
Browser를 disconnect할 때 발생하는 ClientDisconnectionExceptions을 무시한다

<cache dir='cache' size='1024' entries='8192'/>
internal caching을 가능하게 한다.
Dir : cache가 적재될 directory
size : memory size(kb)
entries : entry의 전체 개수

<cache-mapping url-pattern='/' expires='2s'/>
Cache된 파일의 유효시간 일반적으로 운영중에는 15m으로 설정한다.

<servlet-mapping url-pattern='*.xtp' servlet-name='xtp'/>
<servlet-mapping url-pattern='*.jsp' servlet-name='jsp'/>
<host>외부의 servlet 설정이다. 이곳에 위치하면 모든 host에 적용된다.

<servlet-mapping url-pattern='/servlet/*' servlet-name='invoker'/>
URL로부터 servlet명으로 invoke한다. 예를 들어 /examples/basic/servlet/HelloServlet 은 HelloServlet class로부터 시작한다. 일반적으로, 보안상 헛점이 생길 수 있으므로 개발중에만 사용하며 운영중에는 사용하지 않는다.

<welcome-file-list>index.xtp, index.jsp, index.html</welcome-file-list>
시작페이지를 지정한다.


3. <host>의 하위 엘리먼트

<access-log id='logs/access.log'
format='%h %l %u %t "%r" %s %b "%{Referer}i" "%{User-Agent}i"'
rollover-period='1W'/>
<error-log id='logs/error.log'/>
Resin 단독구동 시 로깅을 위한 내용이다.

<war-dir id='webapps'/>
Specifies a special directory to place war file이 위치한 특정 directory를 지정한다.
War directory에 위치한 어떤 .war (web-application resource) file이던지 자동으로 확장/설치 된다. 일반적으로, war file은 설정을 위해 WEB-INF/web.xml 을 사용하며 구문은 다른 application 설정과 동일하다.


4. <web-app>의 하위 엘리먼트

<classpath id='WEB-INF/classes'
source='WEB-INF/classes'
compile='true'/>
classpath를 지정한다. Source는 option이다. Servlets 과 beans는 일반적으로 WEB-INF/classes에 위치한다.

<session-config>
<session-max>4096</session-max>
<session-timeout>30</session-timeout>
<enable-cookies>true</enable-cookies>
<enable-url-rewriting>true</enable-url-rewriting>
<file-store>WEB-INF/sessions</file-store>
</session-config>
세션에 관한 설정이다.
Session-max : 최대 session 개수
Session-timeout : session timeout 시간(초)
Enable-cokkies : 쿠키 사용여부
Enable-url-rewritin :
세션을 아래의 방법중 하나를 사용하여 외부에 적재할 경우 개발 중 class 변경으로 인한 세션 삭제를 방지할 수 있다.
File-store : 세션을 지정된 디렉토리에 적재한다.
tcp-store : tcp-ring을 사용하여 세션을 적재한다.
Jdbc-store : DB table을 사용하여 세션을 적재한다.

<multipart-form upload-max='-1'/>
multipart-mime/form 사용을 가능하게 한다.

<path-mapping url-regexp='^/~([^/]*)' real-path='/home/$1/public_html/'/>
url path를 실제 path에 mapping한다.

<context-param info='An application information string'/>
Application init parameter이다.

<servlet-mapping url-pattern='/snoop/*' servlet-name='snoop-servlet'/>
모든 url에서 /snoop에 대하여 snoop-servlet 이름으로 접근한다.

<servlet servlet-name='snoop-servlet' servlet-class='Env'>
<init-param info='A servlet information string'/>
</servlet>
snoop-servlet init parameter로 info='A servlet information string'를 사용하여 구동한다.