로그 파일 및 콘텐츠에 기록 된 오픈 액세스 로그의 nginx 구성 파일의 문제가 아니라 - 리눅스

하나, 현장 재구성

1, 구성 파일 /nginx/conf/nginx.conf
worker_processes  1;

events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    sendfile        on;

    keepalive_timeout  65;

    server {
        listen       80;
        server_name  localhost;

        location / {
            root   html;
            index  index.html index.htm;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }

    include sites-enabled/*.conf;
}
2, 하나의 프로젝트 프로파일 /nginx/conf/sites-enabled/jean.conf
server {
  listen 80;

  server_name www.jean.com;
  root /mine/serve/project;

  location ~* \.(jpg|jpeg|gif|css|png|js|ico|html)$ {
    access_log off;
    expires max;
  }

  access_log  logs/access.jean.log  main;

  location / {
        index index.html;
        autoindex on;
        autoindex_exact_size on;
        autoindex_localtime on;
  }

  location ~ /\.ht {
    deny  all;
  }

  location ~ \.sh$ {
    deny  all;
  }
}
(3) 시험 환경
[root@192 sbin]# ./nginx -t
nginx: the configuration file /mine/serve/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /mine/serve/nginx/conf/nginx.conf test is successful
4, 도메인 이름에 대한 액세스 
정상 출력!
5 로그보기 
로그 파일을 생성하지 않습니다
[root@192 logs]# ls
access.log  error.log  nginx.pid

둘째, 문제를 식별

1, 프로젝트 프로파일 /nginx/conf/sites-enabled/jean.conf
#可疑代码行
=-----------------------------------------------------=
  location ~* \.(jpg|jpeg|gif|css|png|js|ico|html)$ {
    access_log off;
    expires max;
  }
=-----------------------------------------------------=
참고 : 모든 액세스는 JPG입니다 위의 코드 수단 | JPEG가 | 지프가 | PNG는, CSS는 | JS가 | ICO는, HTML 파일, 로그에 기록되지는 캐시가 최대 값을 유지하는 것입니다!
2, 문제 해결 
밖으로 코멘트를 "오프 ACCESS_LOG;"이 라인 : "# ACCESS_LOG 오프;"다음 다시 시작 nginx를 서비스 
하고, 파일을 nginx.conf (앞의 "#"을 제거) 개방에 log_format 명령 줄을 정의합니다
=-----------------------------------------------------------------------=
log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                  '$status $body_bytes_sent "$http_referer" '
                  '"$http_user_agent" "$http_x_forwarded_for"';
=-----------------------------------------------------------------------=
3, 다시 한 번 도메인 이름을 방문, 로그보기 
과연, 로그 생성을
[root@192 logs]# ls
access.jean.log  access.log  error.log  nginx.pid
[root@192 logs]# ll
总用量 12
-rw-r--r--. 1 root root  194 11月 23 09:58 access.jean.log
-rw-r--r--. 1 root root    0 11月 23 03:12 access.log
-rw-r--r--. 1 root root 1442 11月 23 09:58 error.log
-rw-r--r--. 1 root root    4 11月 23 03:12 nginx.pid
내용이 기록! ! 

네, 그것은 주장 할 수있다 "ACCESS_LOG 로그 / access.jean.log 주요;"그 위에 넣을 [선] # 의심스러운 코드, 나는 할 수 없습니다? 아니, 그러나, 쓰기 내용하지 않습니다하는 access.jean.log 파일을 만듭니다!

셋째, 문제 요약

로그 오류에 대해, 일반적으로이 두 가지 문제가 있습니다 : 
1, 로그에 있지만, 로그를 생성하지 않은, 예 : "ACCESS_LOG 로그 / access.jean.log 주요;"으로 우선, 당신이 로그 명령 줄에서 설정하지 않은 만든다이 상황,, , 명령 행, 만약 그렇다면, 주석, 다시 시작 nginx를 서비스, 다음에는 "오프 ACCESS_LOG"없다 "/nginx/conf/sites-enabled/jean.conf"주 구성 파일 nginx.conf 및 프로젝트 프로필을보고있다 일반적으로 아무 문제. 
log_format : 2, "[EMERG] nginx를"보고 "지시문은 여기 /mine/serve/nginx/conf/sites-enabled/jean.conf:13에서 허용되지 않음" 이 오류는 일반적으로 정의 된 "log_format"nginx를해야합니다 의 .conf 파일이 기본이 형식에 대한 열 주석이, 당신은 또한 당신의 프로젝트 설정 파일에서, 다음, nginx.conf의 구성 파일을 사용자 정의 할 수 있습니다. 
(3) 또한, 로그 형식은 "log_format"정의는 오류가있을 것이다, 그렇지 않으면, 예 : "/nginx/conf/sites-enabled/jean.conf"로, 프로젝트 설정 파일에 정의 할 수 없습니다!
게시 59 개 원래 기사 · 원 찬양 2 · 조회수 5561

추천

출처blog.csdn.net/LDR1109/article/details/103894875