Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 1 down vote accepted

now you can upgrade nginx to 1.9.4

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

see full change log here:

share|improve this answer

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

location / {
   proxy_set_header Accept-Encoding "";
   proxy_set_header Host;

   subs_filter_types text/css text/xml text/css;
   subs_filter http://$host https://$host;

You can add as many filters as you wish. See

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

share|improve this answer
Are you using the built in ngx_http_sub_module ( or the 3rd party plugin – Sascha Mar 31 '15 at 13:49
I'm using the built-in module. You can check your nginx's error.log file to figure out more about the error in your code. – Raees Iqbal Apr 6 '15 at 13:50
subs_filter does not support compressed responses, while sub_filter does, if coupled with gunzip on; – colthreepv Aug 29 '15 at 22:37
@mrgamer when you add proxy_set_header Accept-Encoding "";, the response from original server should be without any encoding. So, subs_filter should work everywhere when this rule added. – Raees Iqbal Aug 31 '15 at 9:53
"should" being the most important word here. Sometimes old/proprietary systems behave in non-standard ways. Anyway in NGINX 1.9.4 you can use multiple sub_filter, so there is not any reason left to use that submodule – colthreepv Aug 31 '15 at 10:21

Check HttpSubsModule module instead. Excerpt from documentation:

Several substitution rules per location can be specified

share|improve this answer
Thanks, AlexD, I am aware of the HttpSubsModule, which is not installed on the shared hosting, I am trying to implement the feature at. Looking for a possible hack or a workaround for the available HttpSubModule. – Sergiks Jun 20 '11 at 9:52

I guess you may setup several locations or server_names with one sub_filter per earch and proxy the request through them.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.