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 log_format with $request_time shows which requests are slow

Nginx
~/tips/tip-nginx-log-format-request-time

log_format timed '$remote_addr "$request" $status $body_bytes_sent '

Adds request and upstream timing to each access log line.

The default combined log format has no timing at all.

log_format timed '$remote_addr "$request" $status $body_bytes_sent '
                 'rt=$request_time urt=$upstream_response_time';
access_log /var/log/nginx/access.log timed;

$request_time is the total time in seconds with millisecond resolution, up to the last byte sent to the client. $upstream_response_time is the time the backend needed. A big gap between them points at a slow client or buffering, and two big numbers point at a slow application. Declare the log_format in the http block, reload nginx, and sort the log on the rt= value with sort to find the worst offenders. A new format name has to be given to access_log, as the last line shows, or the old one stays in use.

Further reading: ngx_http_log_module

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