Forum

Reverse proxy: terminate SSL on proxy + rewrite rules for multiple subdomains

Thomas
21 April 2016, 13:48
Hi!

I want to configure Hiawatha reverse proxy for the following host domain
domain.tld
+ domain.tld must be redirected to www.domain.tld
+ subdomain www.domain.tld/subdir will be redirected to //subdir.domain.tld/
+ SSL termination on reverse proxy means no encryption on backend webservers

I found some rewrite rules, but would ask you to validate if this is applicable to Hiawatha, and if not what the correct syntax should be:
Each request to //domain.tld will be redirected to //www.domain.tld
if ($host ~* ^domain\.tld$) {
rewrite ^(.*) //www.domain.tld$1 permanent;
break;
}

Every request to //www.domain.tld/subdir will be redirected to //subdir.domain.tld/
if ($host ~* ^www\.domain\.tld$) {}
if ($uri ~* ^/$) {
set $dir_subdomain "www";
set $dir_filename "";
}
if ($uri ~* ^/([^/]+)(.*)$) {
set $dir_subdomain $1;
set $dir_filename $2;
}
if (-d /var/www/domain.tld/www/$dir_subdomain) {
rewrite ^(.*)$ //$dir_subdomain.domain.tld$dir_filename permanent;
break;
}

And how can the SSL termination be configured?

THX
This topic has been closed.