RSS구독하기:SUBSCRIBE TO RSS FEED
즐겨찾기추가:ADD FAVORITE
글쓰기:POST
관리자:ADMINISTRATOR
출처 블로그 > [스케치]
원본 http://blog.naver.com/tripsketch/3703720
=======================================================================
출처 : http://www.ricky.co.kr/jsboard/read.php?table=system&no=17&page=1
=======================================================================
[제목] 아파치 로그 파일 - 특이한 녀석들은 따로 담거나 없애기* 제목이 좀 이상하네요........^.^작성자 : 김칠봉 <san2(at)linuxchannel.net>작성일 : 2001. 04. 30대상자 : 초보- 힌트 URL : 임은재님이 쓴 글을 보고 나서   http://kltp.kldp.org/stories.php?story=00/10/22/9724184- 관련 문서 : 아파치 제공 문서   http://httpd.apache.org/docs/mod/mod_log_config.html   http://httpd.apache.org/docs/mod/mod_setenvif.html목차1. 배경2. 기초지식  2-1. 로그포맷과 CustomLog 지시자  2-2. 아파치 환경변수 설정3. 예제  3-1. 특정 IP 주소만 환경변수로 설정하기  3-2. 특정 타입의 파일만 환경변수로 설정하기  3-3. 특정 User-Agent 만 환경변수로 설정하기  3-4.  종합예제 : 사오정(?) 로그 분석 피하기------------------------------------------1. 배경몇 달 전부터 Webalizer 라는 로그 분석기로 제가(이하 '필자') 운영하는 싸이트의로그를 대충 분석(?)해 봤는데 사오정(?) 분석이 되어 버렸더군요.결정적으로 필자가 운영하는 싸이트의 대부분은 php로 구성되어 있는데, 이는 실제로 - 방문자 외에 localhost에서 php가 실행하는 로그 기록 - 로봇들의 접근 기록 - 운영자(필자)가 접근한 로그 기록 등등이 함께 기록되어 있어 순수 방문자 통계에 약간 덜(?) 정확한 통계가 나오더군요. 따라서 이런 유형들의 로그는 없애거나 따로 로그기록하는 것이 낫을 것 같더군요. 위의 내용이 이하 다루는 내용입니다.2. 기초지식2-1. 로그포맷과 CustomLog 지시자Module mod_log_config 은 아파치 기본 모듈입니다.    로그 포맷 스트링    %a : 원격의 IP 주소    %b : 헤더를 포함한 전송량(bytes)    %{var}e : 환경 변수 "var"    %f : 파일이름    %h : 원격의 호스트    %{hdr}i : 서버에 들어오는(요청) 헤더 값 "hdr"    %l : 원격의 로그인 ID(지원한다면)    %{label}n : 다른 모듈에서 "label" 구성    %{hdr}o : 응답 헤더 값 "hdr"    %p : 서버의 Canonical 포트 번호    %P : 자식 프로세스 ID(PID)    %r : 첫번째 요청 라인    %s : 상태코드    %t : 시간 포맷(CLF 포맷)    %{format}t : "format"으로 구성된 시간 포맷    %T : 서버에 요청하는 시간(초)    %u : 원격의 유저이름(인증시)    %U : 요청한 URL    %v : 클라이언트 요청에 따른 Canonical 서버네임    %V : UseCanonicalName 설정에 따른 서버네임일반적으로 아파치를 설치하고 나면, 다음과 같이 기본설정되어 있을 겁니다.(굳지 수정할 필요없음)    LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined    LogFormat "%h %l %u %t \"%r\" %>s %b" common    LogFormat "%{Referer}i -> %U" referer    LogFormat "%{User-agent}i" agent    CustomLog /usr/local/apache/logs/access_log common물론 이 정도는 다 알고 계시리라 믿습니다.    로그 기록 지시자    CookieLog    CustomLog    LogFormat    TransferLogCookieLogs는 제외하고 나머지 지시자에 대해서 알아봅시다.LogFormat 지시자Syntax: LogFormat format|nickname [nickname]Default: LogFormat "%h %l %u %t \"%r\" %>s %b"Context: server config, virtual hostStatus: BaseCompatibility: Nickname only available in Apache 1.3 or laterModule: mod_log_configCustomLog 지시자Syntax: CustomLog file|pipe format|nickname [env=[!]environment-variable]Context: server config, virtual hostStatus: BaseCompatibility: Nickname only available in Apache 1.3 or later.Conditional logging available in 1.3.5 or later.Module: mod_log_configTransferLog 지시자Syntax: TransferLog file|pipeDefault: noneContext: server config, virtual hostStatus: BaseModule: mod_log_configLogFormat 지시자는 앞에서 예제가 있으므로 생략하고 비슷한 기능을 가진CustomLog, TransferLog 지지자에 대해서 잠깐 알아봅시다.둘다 file 에 로그를 기록한다는 면에서는 동일한 기능입니다.(pipe 기능도 동일)    같은점    1. 둘다 file에 로그를 기록한다.    2. |pipe 에 설정한 외부 프로그램을 인자로 사용할 수 있다.    3. 둘다 다중 로그를 사용할 수 있다.    다른점    1. CustomLog 지시자는 LogFormat 지시자에서 설정한 nickname이나 Log format을        인자로 사용할 수 있다.    2. CustomLog 지시자는 환경변수를 인자로 가질 수 있다.따라서,이하 다룰 내용은 환경변수를 설정하고 이 환경변수(env)와 동일(=)하거나 그렇지 않은(!=)특정 유형에 대해서 로그에 기록해야하 하므로 당연히 CustomLog 지시자를 사용해야합니다.*주의)환경변수를 인자로 사용할 경우 하나만 가능.이해가 되셨는지 모르겠네요....2-2. 아파치 환경변수 설정아파치에서 환경변수를 설정하는 방법은 몇가지 있습니다.예를 들어,    - mod_env 모듈에 의한       SetEnv       지시자 이용    - mod_setenvif 모듈에에 의한       BrowserMatch       BrowserMatchNoCase       SetEnvIf       SetEnvIfNoCase       지시자 이용등이 있습니다.여기에서 주로 사용할 지시자는 BrowserMatch 지시자와 SetEnvIf 지시자입니다.*참고)xxxxNoCase 지시자는 대소문자를 구분하지 않겠다는 의미입니다.이 두개의 지시자에 대한 사용법만 간단하게 알아봅시다.BrowserMatch 지시자Syntax: BrowserMatch regex envar[=value] [envar[=value]] ...Default: noneContext: server config, virtual host, directory, .htaccessOverride: FileInfoStatus: BaseModule: mod_setenvifCompatibility: Apache 1.2 and above (in Apache 1.2 this directive was found in thenow-obsolete mod_browser module); use in .htaccess files only supported with1.3.13 and laterSetEnvIf 지시자Syntax: SetEnvIf attribute regex envar[=value] [envar[=value]] ...Default: noneContext: server config, virtual host, directory, .htaccessOverride: FileInfoStatus: BaseModule: mod_setenvifCompatibility: Apache 1.3 and above; the Request_Protocol keyword andenvironment-variablematching are only available with 1.3.7 and later; use in .htaccess files only supportedwith 1.3.13 and later   환경변수 지정 및 값 지정 방법   1.varname, or   2.!varname, or   3.varname=value   예 :   BrowserMatch ^Mozilla forms jpeg=yes browser=netscape   BrowserMatch "^Mozilla/[2-3]" tables agif frames javascript   BrowserMatch MSIE !javascript   BrowserMatchNoCase Robot is_a_robot   SetEnvIfNoCase User-Agent Robot is_a_robot   BrowserMatchNoCase mac platform=macintosh   BrowserMatchNoCase win platform=windows   SetEnvIf Request_URI "\.gif$" object_is_image=gif   SetEnvIf Request_URI "\.jpg$" object_is_image=jpg   SetEnvIf Request_URI "\.xbm$" object_is_image=xbm        :   SetEnvIf Referer www\.mydomain\.com intra_site_referral        :   SetEnvIf object_is_image xbm XBIT_PROCESSING=1   SetEnvIfNoCase Host Apache\.Org site=apache   SetEnvIf 지자자에서 attribute 에 올 수 있는 것들 :   Remote_Host - the hostname (if available) of the client making the request   Remote_Addr - the IP address of the client making the request   Remote_User - the authenticated username (if available)   Request_Method - the name of the method being used (GET, POST, et cetera)   Request_Protocol - the name and version of the protocol with which the request                                    was made (e.g., "HTTP/0.9", "HTTP/1.1", etc.)   Request_URI - the portion of the URL following the scheme and host portion   그외   Host, User-Agent, and Referer 가능   see http://www.rfc-editor.org/rfc/rfc2616.txt따라서,BrowserMatch와 SetEnvIf User-Agent 는 서로 동일하다는 것을 알 수 있을 겁니다.*중요)CustomLog 지자자와 다르게 환경변수 인자에 여러 개를 설정할 수 있음.여기까지 이해가 되셨다면 다음은 보지 않아도 될듯 하군요.......^.^3. 예제3-1. 특정 IP 주소만 환경변수로 설정하기- 환경변수 이름 : do_not_log- 목적 : 이 환경변수에 해당되는 특정 IP 주소는 access_log에 기록하지 않는다.    SetEnvIf Remote_Addr "^127.0.0.1$" do_not_log    SetEnvIf Remote_Addr "^211.35.159.12[89]$" do_not_log    SetEnvIf Remote_Addr "^211.35.159.1[345][0-9]$" do_not_log    위에서 설정한 특정 IP 주소는    127.0.0.1 자기자신을 말하는 루프백 주소    211.35.159.128, 211.35.159.129 두개의 IP 주소    211.35.159.130 ~ 211.35.159.139 10개의 IP 주소    211.35.159.140 ~ 211.35.159.149 10 개의 IP 주소    211.35.159.150 ~ 211.35.159.159 10 개의 IP 주소즉 원격의 IP 주소(Remote_Addr)가 위와 일치하면 do_not_log 환경변수에 지정하는 예임.*참고)^ 은 시작을 의미$ 은 마지막을 의미[0-9] 0~9까지의 숫자중 어느 하나3-2. 특정 타입의 파일만 환경변수로 설정하기    SetEnvIfNoCase Request_URI "\.(gif|jpg|png|css|js|java)$" do_not_log    요청 URI(Request_URI) 파일이    *.gif    *.jpg    *.png    *.css    *.js    *.java    로 끝난 파일인 경우(대소문자를 구별하지 않음) do_not_log 환경변수에 지정함3-3. 특정 User-Agent 만 환경변수로 설정하기- 환경변수 이름 : do_not_log 과 is_a_robot- 목적 : 이 환경변수에 해당되는 특정 User-Agent는 access_log에 기록하지 않고,             따로 로그(robot-log)에 기록하거나 기록하지 않기 위함.    BrowserMatchNoCase "ru-robot" do_not_log is_a_robot    BrowserMatchNoCase "Slurp/si" do_not_log is_a_robot    BrowserMatchNoCase "Mercator" do_not_log is_a_robot    BrowserMatchNoCase "Gulliver" do_not_log is_a_robot    BrowserMatchNoCase "SyncIT/" do_not_log is_a_robot    BrowserMatchNoCase "FAST-WebCrawler" do_not_log is_a_robot    BrowserMatchNoCase "Lycos_Spider" do_not_log is_a_robot    BrowserMatchNoCase "^ia_archive" do_not_log is_a_robot    BrowserMatchNoCase "^tv" do_not_log is_a_robot    BrowserMatchNoCase "Scooter" do_not_log is_a_robot    BrowserMatchNoCase "ZyBorg/" do_not_log is_a_robot    BrowserMatchNoCase "KIT-Fireball" do_not_log is_a_robot    BrowserMatchNoCase "Googlebot/" do_not_log is_a_robot    BrowserMatchNoCase "DIIbot/" do_not_log is_a_robot    BrowserMatchNoCase "teoma_agent3" do_not_log is_a_robot    BrowserMatchNoCase "empas_robot" do_not_log is_a_robot모두 로봇으로 맞게 설정되었는지 모르겠네요...............T.T각각의 정규표현식 조건에 맞는 User-Agent 인 경우, do_not_log 환경변수와is_a_robot 이라는 두개의 환경변수에 설정한 예입니다.is_a_robot 이라고 또 하나의 환경변수를 지정한 이유는 앞서 얘기했듯이이 조건게 맞는 User-Agent가 접근할 경우 따로 로그에 기록하기 위함입니다.이 BrowserMatchNoCase 지시자 대신에 SetEnvIfNoCase User-Agent 로 대신할 수 있는데첫번째 부분을 다음과 같이 설정할 수 있습니다.(둘다 똑 같은 결과임)    SetEnvIfNoCase User-Agent "ru-robot" do_not_log is_a_robot3-4.  종합예제 : 사오정(?) 로그 분석 피하기앞의 3개의 예제를 모두 적용하면 다음과 같습니다.목적은 배경에서 설명했듯이 가능한 access_log 파일에 - 방문자 외에 localhost에서 php가 실행하는 로그 기록은 기록하지 않는다. - 로봇들의 접근 기록은 따로 robot-log 파일에 기록한다. - 운영자가 주고 접근할 IP 주소는 로그에 기록하지 않는다. - *.gif, *.jpg, *.png, *.css, *.js, *.java 등과 같은 파일은 로그에 기록하지 않는다. 이 정도의 조건이라면 가능한 어느 정도 수준으로 순수 방문자의 접근 기록만 access_log 파일에 기록할 수 있습니다. -- httpd.conf(실제로 필자가 운영하는 아파치 설정 내용임) --------------------#### 중간 생략##LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combinedLogFormat "%h %l %u %t \"%r\" %>s %b" commonLogFormat "%{Referer}i -> %U" refererLogFormat "%{User-agent}i" agentLogFormat "%h %l %u %t \"%r\" %>s %b \"%{User-Agent}i\"" use_robot#### 중간 생략#### 환경변수 do_not_log에 일치하지 않은 접근만 access_log 파일에 기록함.##CustomLog /usr/local/apache/logs/access_log combined env=!do_not_log## 중간 생략## 로봇들은 따로 robot_log 파일에 user_robot 포맷에 맞게 기록함##CustomLog /usr/local/apache/logs/robot_log use_robot env=is_a_robot## 중간 생략## 특정 IP 주소는 로그에 기록하지 않는다.## 주로 서버 IP 주소와 운영자가 자주 접속하는 IP 주소들##SetEnvIf Remote_Addr "^127.0.0.1$" do_not_logSetEnvIf Remote_Addr "^211.35.159.12[89]$" do_not_logSetEnvIf Remote_Addr "^211.35.159.1[345][0-9]$" do_not_log## 중간 생략## 주로 이미지 파일을 요청했을 경우 로그에 기록하지 않는다.##SetEnvIfNoCase Request_URI "\.(gif|jpg|png|css|js|java)$" do_not_log## 중간 생략## 로봇들의 환경변수 지정##BrowserMatchNoCase "ru-robot" do_not_log is_a_robotBrowserMatchNoCase "Slurp/si" do_not_log is_a_robotBrowserMatchNoCase "Mercator" do_not_log is_a_robotBrowserMatchNoCase "Gulliver" do_not_log is_a_robotBrowserMatchNoCase "SyncIT/" do_not_log is_a_robotBrowserMatchNoCase "FAST-WebCrawler" do_not_log is_a_robotBrowserMatchNoCase "Lycos_Spider" do_not_log is_a_robotBrowserMatchNoCase "^ia_archive" do_not_log is_a_robotBrowserMatchNoCase "^tv" do_not_log is_a_robotBrowserMatchNoCase "Scooter" do_not_log is_a_robotBrowserMatchNoCase "ZyBorg/" do_not_log is_a_robotBrowserMatchNoCase "KIT-Fireball" do_not_log is_a_robotBrowserMatchNoCase "Googlebot/" do_not_log is_a_robotBrowserMatchNoCase "DIIbot/" do_not_log is_a_robotBrowserMatchNoCase "teoma_agent3" do_not_log is_a_robotBrowserMatchNoCase "empas_robot" do_not_log is_a_robot## 이하 생략##------------------------------------------------------END
2006/09/11 14:11 2006/09/11 14:11
이 글에는 트랙백을 보낼 수 없습니다
웅쓰:웅자의 상상플러스
웅자의 상상플러스
전체 (379)
게임 (5)
영화 (2)
기타 (23)
맛집 (5)
영어 (2)
대수학 (3)
형태소 (5)
Hacking (9)
Linux (112)
HTML (48)
Application_developing (48)
Web_developing (102)
Window (11)
«   2024/03   »
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31            
  1. 2016/01 (1)
  2. 2015/12 (3)
  3. 2015/10 (3)
  4. 2015/03 (2)
  5. 2015/01 (4)