From 59347ba9093fd5272b5f5dc34cd2503a0b411c24 Mon Sep 17 00:00:00 2001 From: Karol Wypchlo Date: Fri, 4 Mar 2022 13:36:31 +0100 Subject: [PATCH] permanent redirect some-portal.com/hns/[domain] to [domain].hns.some-portal.com --- docker/nginx/conf.d/server/server.api | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/docker/nginx/conf.d/server/server.api b/docker/nginx/conf.d/server/server.api index 11a3ee75..113a3c41 100644 --- a/docker/nginx/conf.d/server/server.api +++ b/docker/nginx/conf.d/server/server.api @@ -137,15 +137,13 @@ location /abuse/report { location /hns { include /etc/nginx/conf.d/include/cors; - # match the request_uri and extract the hns domain and anything that is passed in the uri after it - # example: /hns/something/foo/bar matches: - # > hns_domain: something - # > path: /foo/bar/ - set_by_lua_block $hns_domain { return string.match(ngx.var.uri, "/hns/([^/?]+)") } - set_by_lua_block $path { return string.match(ngx.var.uri, "/hns/[^/?]+(.*)") } + rewrite_by_lua_block { + local hns_domain = string.match(ngx.var.uri, "/hns/([^/?]+)") + local path = string.match(ngx.var.uri, "/hns/[^/?]+(.*)") + local hns_subdomain_url = ngx.var.scheme .. "://" .. hns_domain .. ".hns." .. ngx.var.skynet_portal_domain .. path .. ngx.var.is_args .. ngx.var.args - proxy_set_header Host $host; - include /etc/nginx/conf.d/include/location-hns; + return ngx.redirect(hns_subdomain_url, ngx.HTTP_MOVED_PERMANENTLY) + } } location /hnsres {