Datadog: nginx access.log / error.log permission denied

When you check in Datadog logs, sometimes NGINX logs do not appear, You need to check data dog agent in your server by running this command

sudo datadog-agent status

Command above is for Linux. For complete resources you can read here : https://docs.datadoghq.com/agent/guide/agent-commands/?tab=agentv6v7#agent-status-and-information

If you had error, you will find something like this:

==========
Logs Agent
==========

    Sending compressed logs in HTTPS to agent-http-intake.logs.datadoghq.com on port 443
    BytesSent: 0
    EncodedBytesSent: 28
    LogsProcessed: 0
    LogsSent: 0

  nginx
  -----
    - Type: file
      Path: /var/log/nginx/access.log
      Status: Error: open /var/log/nginx/access.log: permission denied
      BytesRead: 0
      Average Latency (ms): 0
      24h Average Latency (ms): 0
      Peak Latency (ms): 0
      24h Peak Latency (ms): 0
    - Type: file
      Path: /var/log/nginx/error.log
      Status: Error: open /var/log/nginx/error.log: permission denied
      BytesRead: 0
      Average Latency (ms): 0
      24h Average Latency (ms): 0
      Peak Latency (ms): 0
      24h Peak Latency (ms): 0

Pay attention for this error Status: Error: open /var/log/nginx/access.log: permission denied. This error said that datadog agent in your server does not has any permission to read the log files or access /var/log/nginx driectory.

How to solve?

Just running these four commands to update the permission rule in your server

chmod 755 /var/log/nginx
chmod 644 /var/log/nginx/*.log
chmod 644 /var/log/nginx/*.gz
nano /etc/logrotate.d/nginx # change 640 to 755 for "create" directive

source: https://dae.me/blog/2591/datadog-nginx-access-log-error-log-permission-denied/

Leave a Comment