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.

I'm setting up a reverse proxy for internal testing of various websites via multiple backends.

In order to be able to dynamically add backends, I'm using a wildcard subdomain and parts of the server_name to extract settings for my Nginx configuration:

server {
    listen 80;
    server_name   ~^(?<domain>.+)\.internal-checks(?<bundle>[0-9])\.mycompany\.com$;


    proxy_set_header Host $domain;
    proxy_pass http://10.0.0.$bundle:8080;

So far, so good. What I'm having an issue with is:

How can I replace all the occurrences of http://$domain with http://$domain.internal-checks$bundle.mycompany.com within the content I receive from the backends?

This needs to be done in order to adjust all the links in the content to match the reverse proxy's wildcard DNS.

My current attempt is to use subs_filter. If I'm using hard coded values the substitutions work:

subs_filter http://www.my-site.com http://www.my-site.com.internal-checks1.mycompany.com r;

But whatever combination I tried, subsitution with variables only ends up with the original content. This is my latest shot:

subs_filter http://$domain http://$domain.internal-checks$bundle.mycompany.com r;

How does subs_filter expect variables to be used?

share|improve this question
sub_filter doesn't accept variables in first argument. Try to use Lua instead wiki.nginx.org/HttpLuaModule#body_filter_by_lua –  Alexey Ten Feb 9 at 10:44
or script the creation of your nginx server blocks so they don't contain variables. –  AD7six Feb 9 at 10:45

Your Answer


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

Browse other questions tagged or ask your own question.