Where Are NGINX Logs Stored? – Location & Useful Commands

Where Are NGINX Logs Stored? – Location & Useful Commands

NGINX caching is highly recommended to make more effective use of server resources. It does not have a negative impact on website performance, as the 

  1. .htaccess
file continues to work correctly.

NGINX Logs per Domain

Logs are stored per domain in separate folders. You can find them at the following path:

  1. /var/log/nginx/domains

Viewing the Logs

To view the last 100 stored log entries for a specific domain, replace "NAME" with the domain name in the following command:

  1. tail -100 /var/log/nginx/domains/NAME

Searching for Specific Log Entries

You can combine commands to search for a specific log entry. For example, to search for an IP access to a particular domain, use the following command, replacing "SEARCH_CRITERIA" with the desired search term and "NAME" with the domain name:

  1. grep -i SEARCH_CRITERIA /var/log/nginx/domains/NAME

 

Practical Example

Let's say you want to view the last 100 log entries for the domain example.com and search for access from the IP 192.168.1.1. The commands would be as follows:

View the last 100 log entries:

  1. tail -100 /var/log/nginx/domains/example.com

Search for access from IP 192.168.1.1:

  1. grep -i "192.168.1.1" /var/log/nginx/domains/example.com

Implementing NGINX caching and properly managing per-domain logs are essential practices for improving the performance and administration of a web server. By following these steps and using the provided commands, you can optimize the operation of your websites and streamline the analysis of access and error logs.