nginx 작업자 프로세스 알림을 억제하는 방법은 무엇입니까?

nginx 작업자 프로세스 알림을 억제하는 방법은 무엇입니까?

참고: 로깅이 비활성화되어 있지만 알림은 계속 표시됩니다!

Docker 컨테이너의 오류만 표시하는 깔끔한 로그를 원하지만, nginx는 오류가 발생하더라도 명령줄에 노이즈를 쏟습니다.모든 것을 비활성화, 이러한 알림을 비활성화할 수 있는 우아한 방법(예: grep을 진입점으로 사용하지 않음)이 있습니까?

이미 NGINX_ENTRYPOINT_QUIET_LOGS=1환경 변수, -q매개변수 및오류 로깅을 완전히 비활성화합니다.(이것은 테스트를 위한 최종 목표가 아닙니다.)

$ docker run -e "NGINX_ENTRYPOINT_QUIET_LOGS=1" nginx:alpine "nginx" "-q" "-g" "daemon off; error_log /dev/null emerg;"                        
2024/02/15 09:38:02 [notice] 1#1: using the "epoll" event method
2024/02/15 09:38:02 [notice] 1#1: nginx/1.25.4
2024/02/15 09:38:02 [notice] 1#1: built by gcc 12.2.1 20220924 (Alpine 12.2.1_git20220924-r10) 
2024/02/15 09:38:02 [notice] 1#1: OS: Linux 6.7.4-arch1-1
2024/02/15 09:38:02 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1073741816:1073741816
2024/02/15 09:38:02 [notice] 1#1: start worker processes
2024/02/15 09:38:02 [notice] 1#1: start worker process 30
2024/02/15 09:38:02 [notice] 1#1: start worker process 31
2024/02/15 09:38:02 [notice] 1#1: start worker process 32
2024/02/15 09:38:02 [notice] 1#1: start worker process 33
2024/02/15 09:38:02 [notice] 1#1: start worker process 34
2024/02/15 09:38:02 [notice] 1#1: start worker process 35
2024/02/15 09:38:02 [notice] 1#1: start worker process 36
2024/02/15 09:38:02 [notice] 1#1: start worker process 37
2024/02/15 09:38:02 [notice] 1#1: start worker process 38
2024/02/15 09:38:02 [notice] 1#1: start worker process 39
2024/02/15 09:38:02 [notice] 1#1: start worker process 40
2024/02/15 09:38:02 [notice] 1#1: start worker process 41
2024/02/15 09:38:02 [notice] 1#1: start worker process 42
2024/02/15 09:38:02 [notice] 1#1: start worker process 43
2024/02/15 09:38:02 [notice] 1#1: start worker process 44
2024/02/15 09:38:02 [notice] 1#1: start worker process 45
2024/02/15 09:38:02 [notice] 1#1: start worker process 46
2024/02/15 09:38:02 [notice] 1#1: start worker process 47
2024/02/15 09:38:02 [notice] 1#1: start worker process 48
2024/02/15 09:38:02 [notice] 1#1: start worker process 49
2024/02/15 09:38:02 [notice] 1#1: start worker process 50
2024/02/15 09:38:02 [notice] 1#1: start worker process 51
2024/02/15 09:38:02 [notice] 1#1: start worker process 52
2024/02/15 09:38:02 [notice] 1#1: start worker process 53
^C2024/02/15 09:38:04 [notice] 1#1: signal 2 (SIGINT) received, exiting
2024/02/15 09:38:04 [notice] 30#30: exiting
2024/02/15 09:38:04 [notice] 32#32: exiting
2024/02/15 09:38:04 [notice] 33#33: exiting
2024/02/15 09:38:04 [notice] 39#39: exiting
2024/02/15 09:38:04 [notice] 37#37: exiting
2024/02/15 09:38:04 [notice] 40#40: exiting
2024/02/15 09:38:04 [notice] 38#38: exiting
2024/02/15 09:38:04 [notice] 31#31: exiting
2024/02/15 09:38:04 [notice] 42#42: exiting
2024/02/15 09:38:04 [notice] 43#43: exiting
2024/02/15 09:38:04 [notice] 35#35: exiting
2024/02/15 09:38:04 [notice] 34#34: exiting
2024/02/15 09:38:04 [notice] 46#46: exiting
2024/02/15 09:38:04 [notice] 36#36: exiting
2024/02/15 09:38:04 [notice] 45#45: exiting
2024/02/15 09:38:04 [notice] 47#47: exiting
2024/02/15 09:38:04 [notice] 49#49: exiting
2024/02/15 09:38:04 [notice] 48#48: exiting
2024/02/15 09:38:04 [notice] 41#41: exiting
2024/02/15 09:38:04 [notice] 44#44: exiting
2024/02/15 09:38:04 [notice] 51#51: exiting
2024/02/15 09:38:04 [notice] 50#50: exiting
2024/02/15 09:38:04 [notice] 52#52: exiting
2024/02/15 09:38:04 [notice] 53#53: exiting
2024/02/15 09:38:04 [notice] 36#36: exit
2024/02/15 09:38:04 [notice] 33#33: exit
2024/02/15 09:38:04 [notice] 30#30: exit
2024/02/15 09:38:04 [notice] 49#49: exit
2024/02/15 09:38:04 [notice] 41#41: exit
2024/02/15 09:38:04 [notice] 37#37: exit
2024/02/15 09:38:04 [notice] 42#42: exit
2024/02/15 09:38:04 [notice] 43#43: exit
2024/02/15 09:38:04 [notice] 35#35: exit
2024/02/15 09:38:04 [notice] 52#52: exit
2024/02/15 09:38:04 [notice] 31#31: exit
2024/02/15 09:38:04 [notice] 34#34: exit
2024/02/15 09:38:04 [notice] 45#45: exit
2024/02/15 09:38:04 [notice] 44#44: exit
2024/02/15 09:38:04 [notice] 46#46: exit
2024/02/15 09:38:04 [notice] 39#39: exit
2024/02/15 09:38:04 [notice] 50#50: exit
2024/02/15 09:38:04 [notice] 32#32: exit
2024/02/15 09:38:04 [notice] 53#53: exit
2024/02/15 09:38:04 [notice] 40#40: exit
2024/02/15 09:38:04 [notice] 48#48: exit
2024/02/15 09:38:04 [notice] 51#51: exit
2024/02/15 09:38:04 [notice] 47#47: exit
2024/02/15 09:38:04 [notice] 38#38: exit
2024/02/15 09:38:04 [notice] 1#1: signal 14 (SIGALRM) received
2024/02/15 09:38:04 [notice] 1#1: signal 17 (SIGCHLD) received from 40
2024/02/15 09:38:04 [notice] 1#1: worker process 40 exited with code 0
2024/02/15 09:38:04 [notice] 1#1: worker process 42 exited with code 0
2024/02/15 09:38:04 [notice] 1#1: signal 29 (SIGIO) received
2024/02/15 09:38:04 [notice] 1#1: signal 17 (SIGCHLD) received from 42
2024/02/15 09:38:04 [notice] 1#1: worker process 39 exited with code 0
2024/02/15 09:38:04 [notice] 1#1: signal 29 (SIGIO) received
2024/02/15 09:38:04 [notice] 1#1: signal 17 (SIGCHLD) received from 37
2024/02/15 09:38:04 [notice] 1#1: worker process 37 exited with code 0
2024/02/15 09:38:04 [notice] 1#1: worker process 46 exited with code 0
2024/02/15 09:38:04 [notice] 1#1: signal 29 (SIGIO) received
2024/02/15 09:38:04 [notice] 1#1: signal 17 (SIGCHLD) received from 46
2024/02/15 09:38:04 [notice] 1#1: worker process 32 exited with code 0
2024/02/15 09:38:04 [notice] 1#1: worker process 48 exited with code 0
2024/02/15 09:38:04 [notice] 1#1: signal 29 (SIGIO) received
2024/02/15 09:38:04 [notice] 1#1: signal 17 (SIGCHLD) received from 47
2024/02/15 09:38:04 [notice] 1#1: worker process 47 exited with code 0
2024/02/15 09:38:04 [notice] 1#1: signal 29 (SIGIO) received
2024/02/15 09:38:04 [notice] 1#1: signal 17 (SIGCHLD) received from 44
2024/02/15 09:38:04 [notice] 1#1: worker process 44 exited with code 0
2024/02/15 09:38:04 [notice] 1#1: signal 29 (SIGIO) received
2024/02/15 09:38:04 [notice] 1#1: signal 17 (SIGCHLD) received from 50
2024/02/15 09:38:04 [notice] 1#1: worker process 45 exited with code 0
2024/02/15 09:38:04 [notice] 1#1: worker process 50 exited with code 0
2024/02/15 09:38:04 [notice] 1#1: signal 29 (SIGIO) received
2024/02/15 09:38:04 [notice] 1#1: signal 17 (SIGCHLD) received from 45
2024/02/15 09:38:04 [notice] 1#1: worker process 51 exited with code 0
2024/02/15 09:38:04 [notice] 1#1: signal 29 (SIGIO) received
2024/02/15 09:38:04 [notice] 1#1: signal 17 (SIGCHLD) received from 33
2024/02/15 09:38:04 [notice] 1#1: worker process 33 exited with code 0
2024/02/15 09:38:04 [notice] 1#1: worker process 43 exited with code 0
2024/02/15 09:38:04 [notice] 1#1: worker process 34 exited with code 0
2024/02/15 09:38:04 [notice] 1#1: signal 29 (SIGIO) received
2024/02/15 09:38:04 [notice] 1#1: signal 17 (SIGCHLD) received from 34
2024/02/15 09:38:04 [notice] 1#1: signal 17 (SIGCHLD) received from 52
2024/02/15 09:38:04 [notice] 1#1: worker process 52 exited with code 0
2024/02/15 09:38:04 [notice] 1#1: signal 29 (SIGIO) received
2024/02/15 09:38:04 [notice] 1#1: signal 17 (SIGCHLD) received from 31
2024/02/15 09:38:04 [notice] 1#1: worker process 31 exited with code 0
2024/02/15 09:38:04 [notice] 1#1: signal 29 (SIGIO) received
2024/02/15 09:38:04 [notice] 1#1: signal 17 (SIGCHLD) received from 36
2024/02/15 09:38:04 [notice] 1#1: worker process 36 exited with code 0
2024/02/15 09:38:04 [notice] 1#1: worker process 41 exited with code 0
2024/02/15 09:38:04 [notice] 1#1: worker process 53 exited with code 0
2024/02/15 09:38:04 [notice] 1#1: signal 29 (SIGIO) received
2024/02/15 09:38:04 [notice] 1#1: signal 17 (SIGCHLD) received from 49
2024/02/15 09:38:04 [notice] 1#1: worker process 30 exited with code 0
2024/02/15 09:38:04 [notice] 1#1: worker process 38 exited with code 0
2024/02/15 09:38:04 [notice] 1#1: worker process 49 exited with code 0
2024/02/15 09:38:04 [notice] 1#1: signal 29 (SIGIO) received
2024/02/15 09:38:04 [notice] 1#1: signal 17 (SIGCHLD) received from 30
2024/02/15 09:38:04 [notice] 1#1: signal 17 (SIGCHLD) received from 35
2024/02/15 09:38:04 [notice] 1#1: worker process 35 exited with code 0
2024/02/15 09:38:04 [notice] 1#1: exit

PS: 문제는 nginx 버전 1.20.0부터 시작됩니다. 버전 1.19.10(최신 1.19 버전)에는 이러한 알림이 없지만 보안 취약점으로 인해 이러한 이전 버전을 사용하고 싶지 않습니다.

그러나 변경 로그에는 이 변경 사항에 대한 언급이 없습니다.http://nginx.org/en/CHANGES-1.20:

Changes with nginx 1.20.0                                        20 Apr 2021
    *) 1.20.x stable branch.

PPS: 이 테스트를 사용하여 모든 로깅을 비활성화합니다 error_log /dev/null emerg;. 이러한 메시지는 일반 로깅 외부에서 nginx에 의해 생성되는 것으로 보입니다.

답변1

사용 중인 Docker 이미지는 nginx:alpine다음 줄을 포함하는 Nginx 구성을 사용합니다.

error_log  /var/log/nginx/error.log notice;

제공된 구성 파일을 추출하고 수정한 다음 컨테이너를 시작하고 수정된 구성 파일을 올바른 위치에 설치해야 합니다.

  1. cat /etc/nginx/nginx.conf컨테이너에서 실행하고 출력을 파일(여기서는 현재 디렉터리에서 사용함)로 리디렉션하여 제공된 my-nginx.conf구성 파일을 가져옵니다.

    docker run --rm --entrypoint=cat nginx:alpine /etc/nginx/nginx.conf >my-nginx.conf
    
  2. 즐겨 사용하는 편집기를 사용하여 위에 표시된 줄의 단어를 notice다음으로 변경하여 파일을 수정하세요. error이렇게 하면 서비스 로그 오류 메시지나 메시지에 더 높은 우선순위가 부여됩니다. GNU를 사용하면 sed다음과 같은 작업을 수행할 수 있습니다.

    sed -i '/^error_log.*notice;/ s/notice/error/' my-nginx.conf
    
  3. 컨테이너를 시작하고 수정된 구성 파일을 에 마운트(읽기 전용)합니다 /etc/nginx/nginx.conf. 여기서는 다음을 테스트합니다 run --rm.

    docker run --rm -v "$PWD/my-nginx.conf":/etc/nginx/nginx.conf:ro nginx:alpine
    

로컬에서 이 작업을 수행하면 다음과 같은 출력이 표시되어 로그 수준이 실제로 더 이상 없음을 나타냅니다 notice.

/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf
10-listen-on-ipv6-by-default.sh: info: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf
/docker-entrypoint.sh: Sourcing /docker-entrypoint.d/15-local-resolvers.envsh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
/docker-entrypoint.sh: Configuration complete; ready for start up

Nginx Docker Hub 페이지의 사용자 정의 구성 섹션도 참조하세요.https://hub.docker.com/_/nginx

답변2

error_log warn;생산에 사용됩니다. 레벨 이상이면 notice개발에 적합합니다.

관련 정보