In this tutorial, you will learn how to read logs generated by Nginx.
Checking logs is a must when it comes to maintaining your web server.
On the log file you will see all the requests that are reaching your server.
This file is automatically generated by Nginx, and it is located on the
To read the log file, there are several ways. Like you can for example simply tail this file, which means you can easily read the content of
access.log directly from your terminal.
Another way of reading this file, is by downloading the log file
access.log on your pc, and reading it using an offline text editor.
Read Nginx Logs
By default, Nginx will store all logs into a file called
access.log If you go to
/var/log/nginx/ directory you can see the
Now to read this file, is very easy.
You can use the
tail command, which allows you to read the content of a file on Linux.
Read Nginx logs in Real Time
tail command without the -f argument, will not be able to read the content of the log file as they are being generated, meaning you won't be able to read the log file on real time.
To be able to read Nginx logs as they are being generated, then you need to use the tail command with
tail -f /var/log/nginx/access.log
Download Nginx Logs on your Machine
There are several ways to copy a file from your server. In this tutorial, we'll be copying
access.log file from
/var/log/nginx/ into our machine using the scp (Secure copy) command.
scp allows you to copy any file from your server to any machine/server.
1) To download access.log into your machine's Desktop, run the command below
scp root@server-ip:/var/log/nginx/access.log ~/Desktop
2) Login to your SSH server
Once you run the scp command above, you will be asked to login on your ssh server, this happens because note the command above we are simply connecting to the ssh server as usual.
3) Read access.log file
And the log file should be now downloaded on your Desktop. To read this file, simply open it with a text editor.
In this tutorial, you learned how to read Nginx's logs. We also explained how to read nginx logs in real time by using the tail command with -f argument.