To view Nginx logs in real-time, you can use the tail -f command:
# Real-time tracking of access log
tail -f /var/log/nginx/access.log
# Real-time tracking of error log
tail -f /var/log/nginx/error.log
The tail command continuously monitors the file for changes and immediately displays any new content added to the file. Press Ctrl + C to stop monitoring.
It can be combined with other commands:
tail -f /var/log/nginx/access.log | grep " 404 "
tail -f /var/log/nginx/access.log | grep "/admin.html"
tail -f /var/log/nginx/access.log | grep "POST"
Monitor multiple files simultaneously:
tail -f access.log errors.log
tail -f /var/log/nginx/*.log
When log rotation occurs, use -F:
# -f tracks the file descriptor; monitoring stops if the file is recreated
tail -f /var/log/nginx/access.log
# -F tracks the filename; monitoring resumes if the file is recreated
tail -F /var/log/nginx/access.log