Nota: O registro está desativado, mas os avisos ainda ocorrem!
Quero um log limpo que mostre apenas erros para meus contêineres Docker, mas o nginx está apenas inundando a linha de comando com ruído, mesmo que eu desabilite tudo . Existe alguma maneira elegante (por exemplo, não usar grep como ponto de entrada) de desabilitar esses avisos?
Já estou usando a NGINX_ENTRYPOINT_QUIET_LOGS=1
variável de ambiente, o -q
parâmetro e desabilitei completamente o log de erros (que não é o objetivo final, mas apenas para teste).
$ 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: O problema começa com o nginx versão 1.20.0. A versão 1.19.10 (a versão 1.19 mais recente) não possui esses avisos, mas por preocupação com vulnerabilidades de segurança, não quero usar uma versão tão antiga.
No entanto, esta mudança não é mencionada no changelog http://nginx.org/en/CHANGES-1.20 :
Changes with nginx 1.20.0 20 Apr 2021
*) 1.20.x stable branch.
PPS: Todo o log está desabilitado para este teste usando error_log /dev/null emerg;
, as mensagens parecem ser emitidas pelo nginx fora do log normal.
A imagem Docker que você usa,
nginx:alpine
usa uma configuração Nginx que inclui a linhaVocê deve extrair o arquivo de configuração fornecido, modificá-lo e, em seguida, iniciar o contêiner com o arquivo de configuração modificado montado no local correto.
Obtenha o arquivo de configuração fornecido simplesmente executando
cat /etc/nginx/nginx.conf
no contêiner e redirecionando a saída para um arquivo (aqui eu usomy-nginx.conf
no diretório atual):Modifique o arquivo com seu editor preferido, alterando a palavra
notice
paraerror
na linha indicada acima. Isso fará com que o serviço registre mensagens de erro ou mensagens com maior prioridade. Com GNUsed
, você pode fazer assim:Inicie o contêiner com o arquivo de configuração modificado montado (somente leitura) em
/etc/nginx/nginx.conf
. Aqui, estou apenas testando comrun --rm
:Quando faço isso localmente, recebo a seguinte saída, mostrando que o nível de log realmente não é mais
notice
:Veja também: A seção "Personalizar configuração" da página Nginx Docker Hub: https://hub.docker.com/_/nginx
Uso
error_log warn;
na produção. Osnotice
níveis superiores são adequados apenas para o desenvolvimento.