From 3469943a0b7b3f2e3cab43f238327e9c87c18ad0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karol=20Wypch=C5=82o?= Date: Thu, 24 Sep 2020 16:33:07 +0200 Subject: [PATCH] Support hns subdomains (#420) * support hns subdomains * document feature --- docker/caddy/Caddyfile | 2 +- docker/nginx/conf.d/client.conf | 32 +++++++++++++++++++++----------- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/docker/caddy/Caddyfile b/docker/caddy/Caddyfile index 77485c4e..0919b586 100644 --- a/docker/caddy/Caddyfile +++ b/docker/caddy/Caddyfile @@ -6,7 +6,7 @@ } (siasky.net) { - siasky.net, *.siasky.net { + siasky.net, *.siasky.net, *.hns.siasky.net { tls { dns route53 } diff --git a/docker/nginx/conf.d/client.conf b/docker/nginx/conf.d/client.conf index 4b36395f..d6df2685 100644 --- a/docker/nginx/conf.d/client.conf +++ b/docker/nginx/conf.d/client.conf @@ -22,9 +22,8 @@ server { listen 80 default_server; listen [::]:80 default_server; - # parse subdomain (a base32 encoded Skylink) into custom variable - server_name "~^([a-z0-9]{55})\..*$"; - set $subdomain $1; + # understand the regex https://regex101.com/r/BGQvi6/2/ + server_name "~^(((?([a-z0-9]{55}))|(?[^\.]+)\.hns)\.)?(?[^.]+)\.(?[^.]+)$"; # ddos protection: closing slow connections client_body_timeout 5s; @@ -36,17 +35,22 @@ server { client_max_body_size 128k; location / { - # The only safe thing to do inside an if in a location block is return - # or rewrite, since we need to proxy_pass we have to work our way around - # using a custom error code. - # + # This is only safe workaround to reroute based on some conditions # See https://www.nginx.com/resources/wiki/start/topics/depth/ifisevil/ - error_page 418 = @subdomain; recursive_error_pages on; - if ($subdomain != "") { + + # redirect links with base32 encoded skylink in subdomain + error_page 418 = @base32_subdomain; + if ($base32_subdomain != "") { return 418; } + # redirect links with handshake domain on hns subdomain + error_page 419 = @hns_domain; + if ($hns_domain != "") { + return 419; + } + include /etc/nginx/conf.d/include/cors; root /var/www/webportal; @@ -233,10 +237,16 @@ server { proxy_pass http://siad/skynet/skylink/$skylink$is_args$args; } - location @subdomain { + location @base32_subdomain { include /etc/nginx/conf.d/include/proxy-buffer; - proxy_pass http://127.0.0.1/$subdomain/$request_uri; + proxy_pass http://127.0.0.1/$base32_subdomain/$request_uri; + } + + location @hns_domain { + include /etc/nginx/conf.d/include/proxy-buffer; + + proxy_pass http://127.0.0.1/hns/$hns_domain/$request_uri; } location ~ "^/file/([a-zA-Z0-9-_]{46}(/.*)?)$" {