multiple sub_filter rules for a reverse proxy on nginx?

Solution 1:

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 2:

Check HttpSubsModule module instead. Excerpt from documentation:

Several substitution rules per location can be specified


Solution 3:

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