multiple sub_filter rules for a reverse proxy on nginx?

with no evil plans I am trying to mirror a site under other domain, while changing a few strings on the fly.

I set up nginx on a new host to serve as a RP to the master site. This allows to set one rule of replacement:

sub_filter      Originalstring  'new string';
sub_filter_once off;

However, I'd like to have several rules running, which sub_filter allows only one per location.

What can be a solution here, if any?


Solution 1:

now you can upgrade nginx to 1.9.4

*) Feature: multiple "sub_filter" directives can be used simultaneously.

see full change log here: http://nginx.org/en/CHANGES

Solution 2:

Unlike the previous one, the current version of nginx allows to create multiple sub filter rules under one location directive. Like so

location / {
   resolver   8.8.8.8;
   proxy_pass http://original-domain.com;
   proxy_set_header Accept-Encoding "";
   proxy_set_header Host original-domain.com;

   subs_filter_types text/css text/xml text/css;
   subs_filter a.original-domain.com b.mydomain.com;
   subs_filter http://$host https://$host;
}

You can add up to 255 filters. See http://wiki.nginx.org/HttpSubsModule

Make sure you have subs_filter installed with nginx by running this command nginx -V. Look for --with-http_sub_module in the output.

Solution 3:

Check HttpSubsModule module instead. Excerpt from documentation:

Several substitution rules per location can be specified