---
title: Enabling App and API Protection for Nginx
description: Datadog, the leading service for cloud-scale monitoring.
breadcrumbs: >-
  Docs > Datadog Security > App and API Protection > Enabling App and API
  Protection > Enabling App and API Protection for Nginx > Enabling App and API
  Protection for Nginx
---

# Enabling App and API Protection for Nginx

{% callout %}
# Important note for users on the following Datadog sites: app.ddog-gov.com

{% alert level="danger" %}
This product is not supported for your selected [Datadog site](https://docs.datadoghq.com/getting_started/site). ().
{% /alert %}

{% /callout %}

The Datadog nginx tracing module has experimental support for threat detection and blocking.

## Enabling threat detection{% #enabling-threat-detection %}

### Get started{% #get-started %}

1. Verify that your nginx build was compiled with the flag `--with-threads`. Most distributions ship with this flag enabled by default. To check if your nginx installation was built with thread support, run `nginx -V` and check the `configure arguments` line. If you cannot find `--with-threads` in the output, you will need to rebuild nginx with this flag enabled. For more information on how to build nginx from sources, see the [nginx documentation](https://nginx.org/en/docs/configure.html).

1. Update your nginx tracing library module to at least version 1.2.0. Visit the [GitHub releases page](https://github.com/DataDog/nginx-datadog/releases) and select the artifact named according to the pattern `ngx_http_datadog_module-appsec-<amd64/arm64>-<nginx version>.so.tgz`. **Note**: This artifact includes `appsec` in the name.

1. Enable App and API Protection in the nginx configuration. Do the following:

   - Define one or more thread pools with the [`thread_pool`](https://nginx.org/en/docs/ngx_core_module.html#thread_pool) directive.
   - Explicitly enable AppSec with [`datadog_appsec_enabled`](https://github.com/DataDog/nginx-datadog/blob/master/doc/API.md#datadog_appsec_enabled-appsec-builds).
   - Map requests to a thread pool or pools that you defined with the directive [`datadog_waf_thread_pool_name`](https://github.com/DataDog/nginx-datadog/blob/master/doc/API.md#datadog_waf_thread_pool_name-appsec-builds).

For example:

   ```nginx
   load_module /path/to/ngx_http_datadog_module.so;
   thread_pool waf_thread_pool threads=4 max_queue=128;
   http {
     datadog_appsec_enabled on;
     datadog_waf_thread_pool_name waf_thread_pool;
   }
   ```

For more information, see the [reference documentation](https://nginx.org/en/docs/configure.html).

After this configuration is complete, the library collects security data from your application and sends it to the Agent. The Agent sends the data to Datadog, where [out-of-the-box detection rules](https://docs.datadoghq.com/security/default_rules/#cat-application-security) flag attacker techniques and potential misconfigurations so you can take steps to remediate.

1. To see App and API Protection threat detection in action, send known attack patterns to your application. For example, trigger the [Security Scanner Detected](https://docs.datadoghq.com/security/default_rules/security-scan-detected/) rule by running a file that contains the following curl script:

   ```
   for ((i=1;i<=250;i++)); do# Target existing service's routescurl https://your-application-url/existing-route -A dd-test-scanner-log;# Target non existing service's routescurl https://your-application-url/non-existing-route -A dd-test-scanner-log;done
```

**Note**: The `dd-test-scanner-log` value is supported in the most recent releases.

A few minutes after you enable your application and send known attack patterns to it, threat information appears in the [Application Signals Explorer](https://app.datadoghq.com/security/appsec) and vulnerability information appears in the [Vulnerabilities explorer](https://app.datadoghq.com/security/appsec/vm/).

{% video
   url="https://datadog-docs.imgix.net/images//security/application_security/appsec-getstarted-threat-and-vuln_2.mp4" /%}

## Using App and API Protection without APM tracing{% #using-app-and-api-protection-without-apm-tracing %}

If you want to use App and API Protection without APM tracing functionality, you can deploy with tracing disabled:

1. Configure your tracing library with the `DD_APM_TRACING_ENABLED=false` environment variable in addition to the `DD_APPSEC_ENABLED=true` environment variable.
1. This configuration will reduce the amount of APM data sent to Datadog to the minimum required by App and API Protection products.

For more details, see [Standalone App and API Protection](https://docs.datadoghq.com/security/application_security/guide/standalone_application_security/).

## Further Reading{% #further-reading %}

- [nginx integration's source code](https://github.com/DataDog/nginx-datadog/)
- [OOTB App and API Protection Rules](https://docs.datadoghq.com/security/default_rules/?category=cat-application-security)
- [Troubleshooting App and API Protection](https://docs.datadoghq.com/security/application_security/troubleshooting)
- [Standalone App and API Protection](https://docs.datadoghq.com/security/application_security/guide/standalone_application_security)
