IntroRecently, we found that one of our applications generates a lot of logs, and most of these logs are nginx's access_log. By default, we collect the standard output into es to analyze the application logs, but many of them are access_log, which may cover up the real error logs. So sometimes we may not want to output these access_logs. The example is as follows: Nginx DockerfileI went to Github to look up Nginx's Dockerfile, docker-nginx/Dockerfile at master · nginxinc/docker-nginx (github.com) You can see that nginx links access_log and error_log to standard output by default, which is why we can see access_log in docker logs or kubectl logs We can execute cat /etc/nginx/nginx.conf in the container to view the default nginx configuration default nginx conf From the above, we can see that the error_log level is notice. If necessary, it can also be configured to warn/error. For specific log configuration, please refer to the official documentation. The configurable log levels are: debug, info, notice, warn, error, crit, alert, emerg access_log can be disabled directly using off or using another path, so that it will not be output directly to standard output and there will not be so many logs. New confIt is more convenient to know how to modify the configuration. We only need to replace the default configuration with our new configuration. The new configuration is as follows: user nginx; worker_processes auto; error_log /var/log/nginx/error.log error; pid /var/run/nginx.pid; events { worker_connections 1024; } http { include /etc/nginx/mime.types; default_type application/octet-stream; access_log off; sendfile on; #tcp_nopush on; keepalive_timeout 65; #gzip on; include /etc/nginx/conf.d/*.conf; } Then in the Dockerfile, overwrite the default configuration with the new one: # Copy custom nginx config COPY /conf/nginx.conf /etc/nginx/nginx.conf MoreIf you want to record access_log but don't want to do it directly, you can configure access_log to another file name, and it will be written to the corresponding configured file, but it will not be output directly to standard output, so that many of the collected logs will not be access_log. If you don't want to log, you can directly use the off configuration to disable access_log. If you want to selectively log, such as not logging 2xx/3xx, you can also log other situations. The nginx documentation also introduces it. You can choose according to your needs. map $status $loggable { ~^[23] 0; default 1; } access_log /path/to/access.log combined if=$loggable; References
This is the end of this article on how to adjust the log level of nginx in Docker. For more information about the log level of nginx in Docker, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: SQL insert into statement writing method explanation
>>: Font Treasure House 50 exquisite free English font resources Part 2
The GROUP BY statement is used in conjunction wit...
The establishment of MySQL index is very importan...
This article example shares the specific code of ...
1. The proxy_pass directive of the 1.ngx_stream_p...
Table of contents 1. Gojs Implementation 1. Drawi...
Initialize Dockerfile Assuming our project is nam...
This article shares the specific code of JavaScri...
The picture is used as the background and the lin...
Table label composition The table in HTML is comp...
Table of contents 1. Main functions 2. Implementa...
Input subsystem framework The linux input subsyst...
Step 1: Add a secondary domain name to the Alibab...
The PC version of React was refactored to use Ama...
environment Hostname ip address Serve Jenkins 192...
Table of contents 1. Template tag in HTML5 2. Pro...