I am trying to delete the content of specific attribute within the HTML content while using sub_filter modul in nginx proxy.
This is an example of the attribute that I am trying to delete its content:
integrity="sha256-JcCQTfQJfXQCI9Pgu4C8DsPBm7t6k/3SvAXTFPsXuBk= sha512-l4H3xn9koLbrXcevxo6Hs0TnepFHVLGgQM9tUMgsYxLDsyfVzWen1sqgozMDp1hh7dF1aR3bhNTp+jjrEBTIIA=="
So far I've tried different variation of regular expresions which should work but actually don't work in nginx, for example this one:
sub_filter integrity=".*?" integrity="";
Is my approach wrong? How can I achieve this task in nginx?
Regex pattern integrity=".*?" is not a valid in sub_filter.
instead u can use subs_filter that add via ngx_http_substitutions_filter_module module
https://docs.nginx.com/nginx/admin-guide/dynamic-modules/http-substitutions-filter/
its content would be:
'integrity="[^"]*"' '' gi;
eg:
http {
server {
listen 80;
server_name example.com;
location / {
subs_filter 'integrity="[^"]*"' '' gi;
subs_filter_once off;
subs_filter_types text/html; # for specific type
}
}
}
if it use php fastcgi
location ~ \.php$ {
subs_filter 'integrity="[^"]*"' '' gi;
subs_filter_once off;
subs_filter_types text/html; # for specific type
#--your php configs--
include snippets/fastcgi-php.conf;
fastcgi_pass php_upstream;
#fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With