Low Orbit Flux Logo 2 F

How do I view NGINX logs?

We’re going to assume that you are running on Ubuntu Linux but this should work almost identically on other Linux distributions.

By default NGINX writes to the following two logs:

The files, owners, and permissions look like this:


user1@zippy-zap:~$ ls -ltr /var/log/nginx/
total 0
-rw-r----- 1 www-data adm 0 Nov 28 15:57 access.log
-rw-r----- 1 www-data adm 0 Nov 28 15:57 error.log
user1@zippy-zap:~$ 

By default, the user www-data and any user in the adm group can view these logs. I happen to be in the adm group so I can view these log files by default. They look like this:

You can view these log files using the cat command like this:


user1@zippy-zap:~$ cat /var/log/nginx/error.log
user1@zippy-zap:~$ cat /var/log/nginx/access.log
192.168.3.22 - - [28/Nov/2021:16:07:03 -0500] "GET / HTTP/1.1" 200 3543 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.77 Safari/537.36"
192.168.3.22 - - [28/Nov/2021:16:07:03 -0500] "GET /icons/ubuntu-logo.png HTTP/1.1" 404 197 "http://192.168.3.22/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.77 Safari/537.36"
192.168.3.22 - - [28/Nov/2021:16:08:41 -0500] "GET /test5 HTTP/1.1" 404 197 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.77 Safari/537.36"
192.168.3.22 - - [28/Nov/2021:16:08:58 -0500] "GET /icons/ubuntu-logo.png HTTP/1.1" 404 197 "http://192.168.3.22/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.77 Safari/537.36"
user1@zippy-zap:~$ 

If you want to follow the logs in real time you can use the tail command with the -f flag like this:


tail -f /var/log/nginx/access.log