---
title: "How to Configure Nginx for Retrace"
slug: "web-log-monitoring-configure-nginx-applications"
description: "Learn how to enable Retrace monitoring for Nginx access logs. Configure log collection, adjust Nginx settings, and set permissions for seamless monitoring."
updated: 2020-02-06T15:27:18Z
published: 2020-02-06T15:27:18Z
---

> ## Documentation Index
> Fetch the complete documentation index at: https://docs.stackify.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Collecting Nginx Logs

To enable Retrace to monitor your Nginx web application access logs:

## Enable Log Collection

In Retrace **Server Settings**, enable the **Nginx Access Logs** option found under **Log Collectors.**

## Configure LogFormat

Adjust your Nginx configuration to include the following:

Add **stackify** log_format.

```
log_format stackify `'$remote_addr $msec "$request" $request_time $status "$http_user_agent"'`;
```

> Note: Nginx allows you to configure multiple access logs for one application. They all will be processed. Nginx also allows you to disable access logs for an application, but enable access logs for particular locations or cases. The monitoring agent will only obtain data from the available logs, so this will not be a real statistic for the whole application.

Update your application's **access_log** to reference the **stackify** log_format.

```
http {
    log_format stackify '$remote_addr $msec "$request" $request_time $status "$http_user_agent"';
    server {
        …
        access_log /var/log/nginx/application_access_log.log stackify;
    }
}
```

## Check Permissions

Ensure that the log file and directory are accessible by the monitoring agent.

- `chmod 755` on the log file directories
- `chmod 744` or similar on the log files

> Note: If you use something like logrotate, be sure to specify the permissions (mode) of the new log file that is created after rotating the old log file out and replacing it.

## Configure Applications

Depending on your setup, use either **Auto Discovery** or **Manual Configuration**.

### Auto Discovery

Auto Discovery option will scan `/var/log/nginx` for Nginx access logs:

Auto discovery can be enabled in `/usr/local/stackify/stackify-agent/stackify-agent.conf`.

```
discovery.nginx=true
```

This can automatically be enabled with the Linux Installer argument `--discovery-nginx`.

### Manual Configuration

Use **Manual Configuration** if auto discovery does not find your access logs or you want to define specific **Application** and **Environment** labels.

Configuration should be added to: `/usr/local/stackify/stackify-agent/stackify-agent.conf`.

For each access log setup the following parameters, `[application]` should be replaced w/ a unique key to group the configuration items together.

```
stackify.nginx.[application].app=Sample Application
stackify.nginx.[application].env=Production
stackify.nginx.[application].accessLog=/var/log/custom/nginx/access.log
```
