Edit WAF configuration
After you’ve added a WAF configuration to your instances, edit your NGINX configuration files to apply the required F5 WAF for NGINX directives. This step ensures that protection is enabled and that your configuration references the correct policy and log profile bundles. You can complete this task using the F5 NGINX Instance Manager web interface or REST API.
Add the F5 WAF for NGINX directives in the appropriate context (http, server, or location). The following example shows a typical configuration:
server {
...
location / {
# Enable F5 WAF for NGINX
app_protect_enable on;
# Reference a custom security policy bundle
app_protect_policy_file /etc/nms/ignore-xss.tgz;
# Enable security logging
app_protect_security_log_enable on;
# Reference the log profile bundle
app_protect_security_log /etc/nms/log-default.tgz /var/log/nginx/security-violations.log;
...
}
}If you’re using NGINX Instance Manager with Security Monitoring, your configuration may already include the following directive:
app_protect_security_log "/etc/nms/secops_dashboard.tgz" syslog:server=127.0.0.1:514;Don’t change this value. For details, see the Security Monitoring setup guide.
If you’re running F5 WAF for NGINX Docker Compose, note the following:
-
Add the
app_protect_enforcer_addressdirective to thehttpcontext:app_protect_enforcer_address 127.0.0.1:50000; -
JSON policies and log profiles aren’t supported. You must precompile and publish them using NGINX Instance Manager. Make sure the
precompiled_publicationsetting in the NGINX Agent configuration is set totrue.
See the F5 WAF for NGINX configuration guide for details.
-
In a web browser, go to the FQDN for your NGINX Instance Manager host and log in. Then, select Instance Manager from the Launchpad menu.
-
In the left menu, select Instances or Instance Groups.
-
From the Actions menu (…), select Edit Config for the instance or group.
-
If you’re using precompiled publication, change any
.jsonfile extensions to.tgz. -
To apply a default policy, select Apply Security, then copy the policy snippet and paste it into your configuration.
-
Add the directives inside an
http,server, orlocationblock. -
Select Publish to push the configuration.
Use tools such ascurlor Postman to send requests to the NGINX Instance Manager REST API. The API base URL ishttps://<NIM-FQDN>/api/[nim|platform]/<API_VERSION>.
All requests require authentication. For details on authentication methods, see the API overview.
You can use the NGINX Instance Manager REST API to deploy your F5 WAF for NGINX configuration.
| Method | Endpoint |
|---|---|
| GET | /api/platform/v1/systems/{systemUID}/instances |
| POST | /api/platform/v1/security/{systemUID}/instances/{nginxUID}/config |
Important:Before deploying a configuration to an instance group, make sure all instances in the group run the same version of F5 WAF for NGINX. Otherwise, deployment may fail.
-
Send a
GETrequest to list all instances. The response includes the unique identifier (UID) of the instance you want to update.shell curl -X GET https://{{NMS_FQDN}}/api/platform/v1/systems/{systemUID}/instances \ -H "Authorization: Bearer <access token>" -
Add the F5 WAF for NGINX configuration to your NGINX config file (
nginx.confor another file in a validconfig_dirspath):-
At a minimum, add the following directive:
app_protect_enable on; -
If precompiled publication is enabled, change any
.jsonpolicy references to.tgz. -
To apply a default policy, use:
app_protect_policy_file /etc/nms/NginxDefaultPolicy.tgz;or
app_protect_policy_file /etc/nms/NginxStrictPolicy.tgz; -
Add the directives to an
http,server, orlocationcontext.
-
-
Encode the updated NGINX configuration file using base64.
base64 -i /etc/nginx/nginx.conf -
Send a
POSTrequest to deploy the configuration. Replace<base64-encoded-content>with your encoded config.shell curl -X POST https://{{NMS_FQDN}}/api/platform/v1/security/{systemUID}/instances/{nginxUID}/config \ -H "Authorization: Bearer <access token>" \ --header "Content-Type: application/json" \ -d '{ "configFiles": { "rootDir": "/etc/nginx", "files": [ { "name": "nginx.conf", "contents": "<base64-encoded-content>" } ] }, "validateConfig": true }'
After publishing the configuration, verify the WAF configuration to confirm that protection is active on your instances.