Hi, I am able to achieve this by writing the following rule which creates a new variable with domain mydomain-com.
if ($host ~* "(\w+)[-.](\w+)") { set $host_new "$1-$2"; } However, its not working for any subdomain like work.mydomain.com , i tried following configs to cover subdomains e.g work-mydomain-com but it didn't worked: if ($host ~* "(\w+)[-.](\w+)[-.](\w+)") { set $host_new "$1-$2-$3"; } ====================================================== Any clue where am i wrong? On Sun, May 12, 2019 at 3:01 PM shahzaib mushtaq <shahzaib...@gmail.com> wrote: > Hi, > > We've running nginx as reverse proxy for backend domain named " > mydomain.com". On proxy server we've setup vhost that covers domain and > all subdomains *.mydomain.com. > > What we need is that if user request to any subdomain like > work.mydomain.com, he should be proxied to single backend mydomain.com > but all underline links e.g css/js should be changed to > *work-mydomain-com.newdomain.com > <http://work-mydomain-com.newdomain.com>* . If second user requests > nginx.mydomain.com, he should be proxied back to single backend *mydomain.com > <http://mydomain.com>* while underline links css/js should be changed to > *nginx-mydomain-com.newdomain.com > <http://nginx-mydomain-com.newdomain.com>.* > > 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 > work.mydomain.com.newdomain.com 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: > > mydomain.com ==> mydomain-com.newdomain.com > work.mydomain.com ==> work-mydomain-com.newdomain.com > nginx.mydomain.com ==> nginx-mydomain-com.newdomain.com > > ==================================================== > > upstream server { > server 10.10.10.10:443; > > } > 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_ciphers > 'ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES128-SHA256:DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES256-GCM-SHA384:AES128-GCM-SHA256:AES256-SHA256:AES128-SHA256:AES256-SHA:AES128-SHA:DES-CBC3-SHA:HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4'; > ssl_prefer_server_ciphers on; > server_name mydomain.com *.mydomain.com; > > > > location / { > > proxy_set_header Accept-Encoding ""; > #subs_filter_types text/css text/xml text/css; > sub_filter "https://mydomain.com" "https://$host.newdomain.com"; > > sub_filter_once off; > proxy_pass https://server; > proxy_set_header HOST mydomain.com; > } > } > >
_______________________________________________ nginx mailing list nginx@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx