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
Preface Recently, my computer often takes a long ...
After installing MySQL, enter mysql -u root -p in...
Table of contents mapState mapGetters mapMutation...
In order to enhance the ability to write JavaScri...
Table of contents 1. Function signature 2. Functi...
This article example shares the specific code of ...
Table of contents 1: Introduction to galera-clust...
By applying it, some public areas of the website c...
Sometimes you need to install certain dependencie...
1. Implementation principle of scrolling The scro...
Phenomenon Start the Docker container docker run ...
<br />How to remove the dividing lines of a ...
We often encounter this situation when doing devel...
When using Navicat to connect to a remote Linux M...
Question 1 solve Start the service: service mysql...