add_header for certain request_uri

Solution 1:

You can set the header using a mapped variable. If the variable is set to an empty string, the header will be silently discarded.

For example:

map $request_uri $myheader {
    ~^/content   a_value;
}
server {
    ...
    add_header X-CUSTOM-HEADER $myheader;

    location / {
        try_files $uri $uri/ /index.html;
    }
}