wordpress – Nginx add_header to wp_admin/admin-ajax.php

I am trying to add a nginx header to the /wp-admin/admin-ajax.php file like so:

location = /wp-admin/admin-ajax.php {
      add_header Content-Security-Policy "default-src 'none'; script-src 'self' 'report-sample'; connect-src 'self' 'report-sample'; img-src 'self' 'report-sample'; style-src 'self' 'report-sample';";
}

But a few blocks down I also have the following

if (!-e $request_filename) {
    rewrite /wp-admin$ $scheme://$host$uri/ permanent;

    rewrite ^/(wp-.*.php)$ /wp/$1 last;
    rewrite ^/(wp-(admin|includes).*) /wp/$1 last;
}

This last block prevents from adding anything to /wp-admin/admin-ajax.php. I don’t quite understand why as I have the feeling im targetting an exact match with the first location block?

Read more here: Source link