Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

3 Answers 3

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

It has been 3 years since this question was asked and a lot has changed. This answer is to help anyone like me. The current version of nginx allows to create multiple sub filter rules under one location directive. Like so

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

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

You can add as many filters as you wish.

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 (nginx.org/en/docs/http/ngx_http_sub_module.html) or the 3rd party plugin wiki.nginx.org/HttpSubsModule? –  Sascha Mar 31 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 at 13:50

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.