Skip to content

Nginx: "add_header" directive is not allowed here in /etc/nginx/waf_patterns/waf_rules.conf #23

Description

@ajn142attamu

Describe the bug
Removing parameters >4096 characters from waf_maps.conf to address #22 results in errors in waf_rules.conf regarding disallowed add_header directive on line 9. Commenting this out results in error moving to line 12, indicating that add_header is not permitted inside of if statements.

To Reproduce
Steps to reproduce the behavior:

  1. Address issues 21 and 22 as listed in descriptions of 22 and 23.
  2. Run nginx -t
  3. See error

Alternately, same issue can be demonstrated by running nginx -t -c against a demo file containing

http {
        server {
                if ($true) {
                        add_header X-Test;
                }
        }
}

Expected behavior
No errors on evaluating configuration.

Error messages/logs

root@instance-20231029-2110:/home/ubuntu# nginx -t
2026/06/08 03:49:03 [emerg] 1169627#1169627: "add_header" directive is not allowed here in /etc/nginx/waf_patterns/waf_rules.conf:12

Environment (please complete the following information):

  • OS: Ubuntu 24.04.1
  • Python Version: N/a
  • Web Server: Nginx 1.24.0
  • Installation Method: downloaded pre-generated configs

Additional context

Research online seems to indicate that using a map is the alternative workflow. I know this project is already using maps, and I don’t understand enough about their use to suggest how this should be implemented instead.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions