brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: nginx access_log with if= keeps health checks out of the log

Nginx
~/tips/tip-nginx-access-log-if-condition

access_log /var/log/nginx/access.log combined if=$loggable;

Skips chosen requests, such as health checks, when writing the access log.

Uptime monitors and container health checks can make up most of an access log.

map $uri $loggable { /healthz 0; default 1; }   # http block
access_log /var/log/nginx/access.log combined if=$loggable;

A request is not logged when the value of the if= variable is 0 or empty. map turns the path into that value, here 0 for /healthz and 1 for everything else. $uri has no query string, so /healthz?x=1 is matched too. The same pattern with a regex such as ~*\.(css|js)$ 0; drops static assets. map is only valid in the http block, so it cannot sit inside a server.

Further reading: ngx_http_log_module: access_log

Going deeper: 🛜 Guide: AdGuard Home + Tailscale (Secure Split-Horizon DNS)

More Nginx tips sudo certbot --nginx -d example.com -d www.example.com /data/nginx/custom/server_redirect.conf map $http_upgrade $connection_upgrade { proxy_intercept_errors on; proxy_redirect http://localhost:3000/ /app/; All Nginx tips (50) All topics

Link