Sobes.tech
Junior — Middle

How can you view Nginx logs for request analysis and server status?

sobes.tech AI

Answer from AI

Nginx logs are usually located in the /var/log/nginx/ directory. The main files are access.log and error.log.

  • access.log contains information about all requests to the server: client IP, request time, method, URL, response code, etc.
  • error.log records errors and warnings occurring during server operation.

To view the logs, you can use commands:

# View the last lines of access.log
sudo tail -f /var/log/nginx/access.log

# View the last lines of error.log
sudo tail -f /var/log/nginx/error.log

# Search for a keyword
sudo grep "404" /var/log/nginx/access.log

You can also configure the log format in the Nginx configuration for more detailed analysis.