오류 로그 구성 및 액세스 로그 구성 및 로그 기록

WBOY
풀어 주다: 2016-07-28 08:29:02
원래의
1165명이 탐색했습니다.

错误log配置和访问log配置
[root@slave nginx]# vi /etc/nginx/nginx.conf
worker_processes 1;
error_log /var/log/nginx/error.log;
이벤트 {
     worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
log_format comman '$remote_addr - $remote_user [$time_local] "$request" '
                     '$status $body_bytes_sent "$http_referer" '
                     '"$http_user_agent" "$request_body" "$request_time"';
    서버 {
        듣기       80;
        server_name  www.wolf.com Wolf.com;
        위치 / {
            루트   html/www;
            index  index.html index .htm;
}
    access_log  /var/log/nginx/www.log  comman;
    }
    서버 {
        듣기       80;
        server_name  bbs.wolf.com;
        위치 / {
            루트   html/bbs;
            인덱스  index.html index.htm;
        }
    }
    서버 {
        듣기       80;
       server_name  blog.wolf.com;
        위치 / {
            루트   html/blog;
            index  index.html index.htm;
        }
    }
   ##status
   서버 {
        듣기      80;
        서버_이름 status.wolf.com;
        위치 / {
            stub_status on;
            access_log off;
        }
    }
}
配置完毕,测试如下
[root@ 슬레이브 nginx]# 컬 www.wolf.com
http://www.wolf.com
[root@slave nginx]# tail -f www.log
192.168.0.203 - - [11/6월 /2016:16:26:52 +0800] "GET / HTTP/1.1" 200 20 "-" "curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.14.0.0 zlib/ 1.2.3 libidn/1.18 libssh2/1.4.2" "-" "0.000"

통통过浏览器访问测试

================ =============================================

로그는 통계적 문제 해결에 매우 유용합니다.
이 글에는 access_log, log_format, open_log_file_cache
, log_not_found, log_subrequest, rewrite_log, error_log 등 nginx 로그 관련 구성이 요약되어 있습니다.
nginx에는 매우 유연한 로깅 모드가 있습니다. 각 구성 수준에는 고유한 독립적인 액세스 로그가 있을 수 있습니다.
로그 형식은 log_format 명령을 통해 정의됩니다.
ngx_http_log_module은 요청 로그 형식을 정의하는 데 사용됩니다.
1. access_log 명령
구문: access_log 경로 [형식 [버퍼=크기 [플러시=시간]]];
access_log 경로 형식 gzip[=레벨] [버퍼=크기] [플러시=시간];
access_log syslog:서버=주소[,매개변수=값] [형식];
access_log off;
기본값: access_log 로그/access.log 결합;
구성 섹션: http, 서버, 위치 , 위치에 있는 경우 제한_제외
gzip 압축 수준.
buffer는 메모리 버퍼 크기를 설정합니다.
플러시가 캐시 영역에 저장되는 최대 시간입니다.
로그를 기록하지 않음: access_log off;
기본 결합 형식을 사용하여 로그를 기록합니다: access_loglogs/access.log 또는 access_loglogs/access.log결합;
log_format 명령
구문: log_format name string …;
기본값: log_format 결합 “…”;
구성 섹션: http
name은 형식 이름을 나타내고 string은 해당 형식을 나타냅니다.
log_format에는 설정할 필요가 없는 기본 결합 로그 형식이 있으며 이는 아래와 같이 Apache의 결합 로그 형식과 동일합니다.
log_format 결합 '$remote_addr - $remote_user [$time_local]'
" " $status $body_bytes_sent'
' "$http_referer" "$http_user_agent" ';
nginx가 로드 밸런서, 오징어 또는 nginx 리버스 프록시 뒤에 있는 경우 웹 서버는 클라이언트의 실제 IP 주소를 직접 얻을 수 없습니다. .
$remote_addr은 역방향 프록시의 IP 주소를 가져옵니다. 역방향 프록시 서버는 전달된 요청의 http 헤더 정보에 X-Forwarded-For 정보를 추가할 수 있습니다.
는 클라이언트 IP 주소와 클라이언트가 요청한 서버 주소를 기록하는 데 사용됩니다.
PS: 다음과 같이 http://www.ttlsa.com/html/2235.html을 참조하세요.
log_format porxy '$http_x_forwarded_for - $remote_user [$time_local]'
                                        $ request" $status $body_bytes_sent '
" "$http_referer" "$http_user_agent" ' $remote_user는 클라이언트 사용자 이름을 기록합니다
$request는 요청된 URL 및 HTTP 프로토콜을 기록합니다
$status는 요청 상태를 기록합니다
$body_bytes_sent 응답 헤더의 크기를 제외한 클라이언트로 전송된 바이트 수입니다. 이 변수는 Apache 모듈 mod_log_config의 "%B" 매개변수와 동일합니다.
$bytes_sent 클라이언트로 전송된 총 바이트 수입니다.
$connection 연결의 일련번호입니다.
$connection_requests 연결을 통해 수신된 현재 요청 수입니다.
$msec 로그 작성 시간. 단위는 초, 정밀도는 밀리초입니다.
$pipe 요청이 HTTP 파이프라인(파이프라인)을 통해 전송되는 경우 파이프 값은 "p"이고, 그렇지 않으면 "."입니다.
$http_referer는 어떤 페이지 링크에 액세스했는지 기록합니다.
$http_user_agent는 클라이언트 브라우저 관련 정보를 기록합니다
$request_length 요청 길이(요청 줄, 요청 헤더 및 요청 본문 포함)입니다.
$request_time 요청 처리 시간, 단위는 초, 정밀도는 클라이언트로 읽혀진 첫 번째 바이트부터 시작하여 마지막 문자가 클라이언트로 전송되고 로그가 기록될 때까지입니다.
$time_iso8601 ISO8601 표준 형식의 현지 시간입니다.
$time_local 공통 로그 형식의 현지 시간입니다.
[경고]클라이언트에 전송된 응답 헤더에는 "sent_http_" 접두사가 있습니다. 예를 들어 $sent_http_content_range입니다. [/warning]
예제는 다음과 같습니다.
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
                    '"$status" $body_bytes_sent "$ http_referer " '
'"$ http_user_agent" "$ http_x_Forwardded_For"'
"$ gzip_ratio" $ request_time $ bytes_SENT $ request_length '; rcache_log '$ 원격_addr -$ 원격_사용자 [$ Time_local] "$ 요청 " '
'"$status" $body_bytes_sent $request_time $bytes_sent $request_length ' _status] [$srcache_expire]';

open_log_file_cache max= 1000 inactive=60s;

서버 {
서버_이름 ~^ (www.)?(.+)$;
access_loglogs/$2-access.log main;
error_loglogs/$2 -error.log;

위치 /srcache {
access_log logs/access-srcache.log srcache_log;
}
}
}

3. open_log_file_cache 명령
구문: open_log_file_cache max=N [inactive=time] [min_uses=N] [valid=time];
open_log_file_cache off;
기본값: open_log_file_cache off;
구성 섹션: http, 서버, 위치
각 로그 기록에 대해 파일이 먼저 열린 다음 다음에 기록됩니다. 로그를 확인한 후 닫았습니다. open_log_file_cache를 사용하여 로그 파일 캐시를 설정할 수 있습니다(기본값은 꺼짐). 형식은 다음과 같습니다.
매개변수 설명은 다음과 같습니다.
max: 캐시에 있는 최대 파일 설명자 수를 설정합니다. 캐시가 가득 차면 LRU 알고리즘을 사용하여 기호가 닫혔음을 설명합니다.
inactive: 생존 시간을 설정합니다. 기본값은 10초입니다.
min_uses: 로그 파일 설명자가 캐시에 기록되기 전 비활성 기간 동안 로그 파일이 사용되는 최소 횟수를 설정합니다. 기본값은 1입니다. time
valid : 확인 빈도 설정, 기본값 60초
off: 캐시 비활성화
예는 다음과 같습니다.
open_log_file_cache max=1000 inactive=20s valid=1m min_uses=2;
4. log_not_found 명령
구문: log_not_found on | off;
기본값: log_not_found on;
구성 섹션: http, server, location
error_log에 존재하지 않는 오류를 기록할지 여부. 기본값은 예입니다.
5. log_subrequest 명령
구문: log_subrequest on | off;
기본값: log_subrequest off;
구성 섹션: http, server, location
하위 요청의 액세스 로그를 기록할지 여부 access_log 에 있습니다. 기본적으로 기록되지 않습니다.
6. rewrite_log 명령
은 ngx_http_rewrite_module 모듈에서 제공됩니다. 재작성 로그를 기록하는 데 사용됩니다. 디버깅 재작성 규칙을 활성화하는 것이 좋습니다. Nginx 재작성 규칙 가이드
구문: rewrite_log on | off;
기본값: rewrite_log off;
구성 섹션: http, server, location, if
활성화되면 알림 수준이 오류 로그 다시 쓰기 로그.
7. error_log 명령
stderr | syslog:server=address[,parameter=value] [debug | error | 값: error_loglogs/error.logerror;
구성 섹션: main, http, server, location
오류 로그를 구성합니다.


이 글에는 access_log, log_format, open_log_file_cache
, log_not_found, log_subrequest, rewrite_log, error_log 등 nginx 로그 관련 구성이 요약되어 있습니다.
nginx에는 매우 유연한 로깅 모드가 있습니다. 각 구성 수준에는 고유한 독립적인 액세스 로그가 있을 수 있습니다.
로그 형식은 log_format 명령을 통해 정의됩니다.
ngx_http_log_module은 요청 로그 형식을 정의하는 데 사용됩니다.
1. access_log 명령
구문: access_log 경로 [형식 [버퍼=크기 [플러시=시간]]];
access_log 경로 형식 gzip[=레벨] [버퍼=크기] [플러시=시간];
access_log syslog:서버=주소[,매개변수=값] [형식];
access_log off;
기본값: access_log 로그/access.log 결합;
구성 섹션: http, 서버, 위치 , 위치에 있는 경우 제한_제외
gzip 압축 수준.
buffer는 메모리 버퍼 크기를 설정합니다.
플러시가 캐시 영역에 저장되는 최대 시간입니다.
로그를 기록하지 않음: access_log off;
기본 결합 형식을 사용하여 로그를 기록합니다: access_loglogs/access.log 또는 access_loglogs/access.log결합;
log_format 명령
구문: log_format name string …;
기본값: log_format 결합 “…”;
구성 섹션: http
name은 형식 이름을 나타내고 string은 해당 형식을 나타냅니다.
log_format에는 설정할 필요가 없는 기본 결합 로그 형식이 있으며 이는 아래와 같이 Apache의 결합 로그 형식과 동일합니다.
log_format 결합 '$remote_addr - $remote_user [$time_local]'
" " $status $body_bytes_sent'
' "$http_referer" "$http_user_agent" ';
nginx가 로드 밸런서, 오징어 또는 nginx 리버스 프록시 뒤에 있는 경우 웹 서버는 클라이언트의 실제 IP 주소를 직접 얻을 수 없습니다. .
$remote_addr은 역방향 프록시의 IP 주소를 가져옵니다. 역방향 프록시 서버는 전달된 요청의 http 헤더 정보에 X-Forwarded-For 정보를 추가할 수 있습니다.
는 클라이언트 IP 주소와 클라이언트가 요청한 서버 주소를 기록하는 데 사용됩니다.
PS: 다음과 같이 http://www.ttlsa.com/html/2235.html을 참조하세요.
log_format porxy '$http_x_forwarded_for - $remote_user [$time_local]'
                                        $ request" $status $body_bytes_sent '
" "$http_referer" "$http_user_agent" ' $remote_user는 클라이언트 사용자 이름을 기록합니다
$request는 요청된 URL 및 HTTP 프로토콜을 기록합니다
$status는 요청 상태를 기록합니다
$body_bytes_sent 응답 헤더의 크기를 제외한 클라이언트로 전송된 바이트 수입니다. 이 변수는 Apache 모듈 mod_log_config의 "%B" 매개변수와 동일합니다.
$bytes_sent 클라이언트로 전송된 총 바이트 수입니다.
$connection 연결의 일련번호입니다.
$connection_requests 연결을 통해 수신된 현재 요청 수입니다.
$msec 로그 작성 시간. 단위는 초, 정밀도는 밀리초입니다.
$pipe 요청이 HTTP 파이프라인(파이프라인)을 통해 전송되는 경우 파이프 값은 "p"이고, 그렇지 않으면 "."입니다.
$http_referer는 어떤 페이지 링크에 액세스했는지 기록합니다.
$http_user_agent는 클라이언트 브라우저 관련 정보를 기록합니다
$request_length 요청 길이(요청 줄, 요청 헤더 및 요청 본문 포함)입니다.
$request_time 요청 처리 시간, 단위는 초, 정밀도는 클라이언트로 읽혀진 첫 번째 바이트부터 시작하여 마지막 문자가 클라이언트로 전송되고 로그가 기록될 때까지입니다.
$time_iso8601 ISO8601 표준 형식의 현지 시간입니다.
$time_local 공통 로그 형식의 현지 시간입니다.
[경고]클라이언트에 전송된 응답 헤더에는 "sent_http_" 접두사가 있습니다. 예를 들어 $sent_http_content_range입니다. [/warning]
예제는 다음과 같습니다.
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
                    '"$status" $body_bytes_sent "$ http_referer " '
'"$ http_user_agent" "$ http_x_Forwardded_For"'
"$ gzip_ratio" $ request_time $ bytes_SENT $ request_length '; rcache_log '$ 원격_addr -$ 원격_사용자 [$ Time_local] "$ 요청 " '
'"$status" $body_bytes_sent $request_time $bytes_sent $request_length ' _status] [$srcache_expire]';

open_log_file_cache max= 1000 inactive=60s;

서버 {
서버_이름 ~^ (www.)?(.+)$;
access_loglogs/$2-access.log main;
error_loglogs/$2 -error.log;

위치 /srcache {
access_log logs/access-srcache.log srcache_log;
}
}
}

3. open_log_file_cache 명령
구문: open_log_file_cache max=N [inactive=time] [min_uses=N] [valid=time];
open_log_file_cache off;
기본값: open_log_file_cache off;
구성 섹션: http, 서버, 위치
각 로그 기록에 대해 파일이 먼저 열린 다음 다음에 기록됩니다. 로그를 확인한 후 닫았습니다. open_log_file_cache를 사용하여 로그 파일 캐시를 설정할 수 있습니다(기본값은 꺼짐). 형식은 다음과 같습니다.
매개변수 설명은 다음과 같습니다.
max: 캐시에 있는 최대 파일 설명자 수를 설정합니다. 캐시가 가득 차면 LRU 알고리즘을 사용하여 기호가 닫혔음을 설명합니다.
inactive: 생존 시간을 설정합니다. 기본값은 10초입니다.
min_uses: 로그 파일 설명자가 캐시에 기록되기 전 비활성 기간 동안 로그 파일이 사용되는 최소 횟수를 설정합니다. 기본값은 1입니다. time
valid : 확인 빈도 설정, 기본값 60초
off: 캐시 비활성화
예는 다음과 같습니다.
open_log_file_cache max=1000 inactive=20s valid=1m min_uses=2;
4. log_not_found 명령
구문: log_not_found on | off;
기본값: log_not_found on;
구성 섹션: http, server, location
error_log에 존재하지 않는 오류를 기록할지 여부. 기본값은 예입니다.
5. log_subrequest 명령
구문: log_subrequest on | off;
기본값: log_subrequest off;
구성 섹션: http, server, location
하위 요청의 액세스 로그를 기록할지 여부 access_log 에 있습니다. 기본적으로 기록되지 않습니다.
6. rewrite_log 명령
은 ngx_http_rewrite_module 모듈에서 제공됩니다. 재작성 로그를 기록하는 데 사용됩니다. 디버깅 재작성 규칙을 활성화하는 것이 좋습니다. Nginx 재작성 규칙 가이드
구문: rewrite_log on | off;
기본값: rewrite_log off;
구성 섹션: http, server, location, if
활성화되면 알림 수준이 오류 로그 다시 쓰기 로그.
7. error_log 명령
stderr | syslog:server=address[,parameter=value] [debug | error | 값: error_loglogs/error.logerror;
구성 섹션: main, http, server, location
오류 로그를 구성합니다.




이상 내용을 포함하여 오류 로그 구성, 액세스 로그 구성 및 로그 기록을 소개했습니다. PHP 튜토리얼에 관심이 있는 친구들에게 도움이 되기를 바랍니다.

관련 라벨:
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!