Skip to main content

Apache에서 response header를 포함하여 캐싱하기

Apache의 mod_asis 모듈


정적 파일만을 캐싱하고자 하는 경우는, Apache의 Alias로 대응하면 된다.
그러나 가끔 HTTP의 Response Header 정보도 Application에 반환해야 하는 경우가 있다.
이 때 mod_asis를 활용하여, 캐싱할 수 있다.


1) mod_asis 설정

httpd.conf 등의 apache 설정 파일에 아래 내용을 추가한다.

LoadModule asis_module lib/modules/mod_asis.so




        AddHandler send-as-is asis
        RewriteEngine On
        RewriteRule ^특정URI$ /filepath/filename.asis [NC,L]




파일 확장자를 asis로 해두는 것이 좋다.

2) response 용 파일 만들기

위에서의 filename.asis의 내용은 다음과 같이 curl --head로 취득한 Response Header 내용과 response body으로 구성하면 된다.
주의점: http://httpd.apache.org/docs/2.2/mod/mod_asis.html의 Notes란에서 언급하듯, Server: 와 Date: 헤더는 삭제해야 한다. 이 정보는 Apache가 알아서 생성해주는 정보이기 때문이다. 이뿐만 아니라, Status 헤더도 없어도 동작하는데 문제 없다.



HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
X-Embedded-Crowd-Version: Crowd/2.4.2
X-Crowd-User-Management-Version: 1.2
Set-Cookie: JSESSIONID=D05FCBE668C69632C3E9FAA6FD14C1C6; Path=/crowd
Content-Type: application/xml
Content-Length: 153
Date: Fri, 30 May 2014 07:26:43 GMT

파일내용


주의점: Header와 Body 사이에는 공백라인 하나 추가하기

3) 내용 확인
apache의 access log를 확인하여, asis 모듈이 잘 동작하는지 확인한다.
참고로 header 정보 오류가 발생할 수 있으니, 다음과 같이 errorlog에 기록하여 확인하는게 좋다.
ErrorLog /log/httpd/error.log


Comments