rewrite hostname in sub_filter!

shahzaib mushtaq shahzaib.cb at
Sun May 12 10:01:24 UTC 2019


We've running nginx as reverse proxy for backend domain named "".
On proxy server we've setup vhost that covers domain and all subdomains *.

What we need is that if user request to any subdomain like,
he should be proxied to single backend but all underline links
e.g css/js should be changed to *
<>* . If second user requests, he should be proxied back to single backend *
<>* while underline links css/js should be changed
to *

As you can see we want all dots in domain/subdomain to be changed to hyphen

I am able to change css/js links using sub_filter to by making use of $host param but i am
struggling on changing it to hyphens.

Please check this nginx config and advise on how to change hostname from
dots to hyphen in sub_filter e.g: ==> ==> ==>


upstream server {

server {
    listen      80;
    listen 443 ssl http2;
    ssl_certificate /etc/ssl/certs/mydomain/mydomain.crt;
    ssl_certificate_key /etc/ssl/certs/mydomain/privkey1.pem;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;
    server_name *;

    location / {

        proxy_set_header Accept-Encoding "";
        #subs_filter_types text/css text/xml text/css;
        sub_filter "" "https://$";

        sub_filter_once off;
        proxy_pass https://server;
        proxy_set_header HOST;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the nginx mailing list