Nginx 접근 로그(accesslog)설정

3519 단어 수송 하 다.
Nginx 접근 로 그 는 주로 두 개의 매개 변수 제어 가 있 습 니 다.
log_format\#로 그 를 기록 하 는 형식 을 정의 합 니 다.(다양한 로그 형식 을 정의 할 수 있 고 이름 을 바 꾸 면 됩 니 다.)
access_log\#일부 파일 의 경로 와 사용 할 로그 형식 기록 로 그 를 지정 합 니 다.
lof_format 의 기본 값:
#    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
#                      '$status $body_bytes_sent "$http_referer" '
#                      '"$http_user_agent" "$http_x_forwarded_for"';

access_log 의 기본 값:
#access_log  logs/access.log  main;

log_format 문법 형식 및 매개 변수 문법 설명 은 다음 과 같 습 니 다.
 log_format        ;

                           

       :     error_log    
        :                     
        :       

 

log_format    :

    $remote_addr  #            
    $remote_user  #        
    $time_local  #         
    $request  #   http       
    $status  #http   ,          ,  :200、301、404 
    $body_bytes_sent  #            body   
    $http_referer  #                 ,              。
    $http_user_agent  #         ,  :   、      
    $http_x_forwarded_for  #          ,  web            ,                     x_forwarded_for  

access_log 문법 형식 및 매개 변수 문법 설명 은 다음 과 같 습 니 다.
    access_log        ;
                           

 

       :     error_log    
        :             
        :              


    :

    access_log    off;  #  access_log,        
    access_log path [format [buffer=size [flush=time]] [if=condition]];
    access_log path format gzip[=level] [buffer=size] [flush=time] [if=condition];
    access_log syslog:server=address[,parameter=value] [format [if=condition]];

      :
    buffer=size  #             
    flush=time  #              
    gzip[=level]  #      
    [if = condition]  #      

일반 장면 의 이런 매개 변 수 는 설정 할 필요 가 없고 극단 적 인 최적화 가 있어 야 이런 매개 변 수 를 고려 할 수 있다.
lof_format 매개 변수의 탭 위치:
http
access_log 매개 변수의 탭 위치:
http, server, location, if in location, limit_except
    :http://nginx.org/en/docs/http/ngx_http_log_module.html

Nginx 접근 로그 프로 세 스 설정:
(1)log 생 성format 구문
worker_processes  1;
error_log logs/error.log error;
events {
    worker_connections  1024;
}
http {
    include status.conf;
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                               '$status $body_bytes_sent "$http_referer" '
                               '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  logs/access.log  main;
    server {
        listen       80;
        server_name  localhost;
                rewrite ^/.* http://www.wl.com permanent;
    }
    include vhost/*.conf;
}

(2)access 삽입로그 문
server {
        access_log /data/log/www;
        listen 80;
        server_name abc.com www.wl.com;

        location / {
                root /data/www/www;
                index index.html index.htm;
        }
        error_log    logs/error_www.wl.com.log    error;
        access_log    logs/access_www.wl.com.log    main;
        #    ↑

}

(3)서비스 재 개
nginx -t
nginx -s reload

다음으로 전송:https://www.cnblogs.com/xuyuQAQ/p/8728773.html

좋은 웹페이지 즐겨찾기