From 8a536cf43cecdda07d5d80c82865443cee323834 Mon Sep 17 00:00:00 2001 From: Karol Wypchlo Date: Wed, 16 Feb 2022 15:09:33 +0100 Subject: [PATCH] use ngx.var.scheme instead of https --- docker/nginx/conf.d/include/location-hns | 4 ++-- docker/nginx/conf.d/include/location-skylink | 4 ++-- docker/nginx/conf.d/server/server.api | 12 ++++++------ docker/nginx/nginx.conf | 4 ++-- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/docker/nginx/conf.d/include/location-hns b/docker/nginx/conf.d/include/location-hns index c8f08d2e..b0c7322d 100644 --- a/docker/nginx/conf.d/include/location-hns +++ b/docker/nginx/conf.d/include/location-hns @@ -81,8 +81,8 @@ proxy_pass https://127.0.0.1/$skylink$path$is_args$args; # in case siad returns location header, we need to replace the skylink with the domain name header_filter_by_lua_block { - ngx.header["Skynet-Portal-Api"] = "https://" .. os.getenv("PORTAL_DOMAIN") - ngx.header["Skynet-Server-Api"] = "https://" .. os.getenv("SERVER_DOMAIN") + ngx.header["Skynet-Portal-Api"] = ngx.var.scheme .. "://" .. os.getenv("PORTAL_DOMAIN") + ngx.header["Skynet-Server-Api"] = ngx.var.scheme .. "://" .. os.getenv("SERVER_DOMAIN") if ngx.header.location then -- match location redirect part after the skylink diff --git a/docker/nginx/conf.d/include/location-skylink b/docker/nginx/conf.d/include/location-skylink index e26844c7..cf250cea 100644 --- a/docker/nginx/conf.d/include/location-skylink +++ b/docker/nginx/conf.d/include/location-skylink @@ -82,8 +82,8 @@ access_by_lua_block { } header_filter_by_lua_block { - ngx.header["Skynet-Portal-Api"] = "https://" .. os.getenv("PORTAL_DOMAIN") - ngx.header["Skynet-Server-Api"] = "https://" .. os.getenv("SERVER_DOMAIN") + ngx.header["Skynet-Portal-Api"] = ngx.var.scheme .. "://" .. os.getenv("PORTAL_DOMAIN") + ngx.header["Skynet-Server-Api"] = ngx.var.scheme .. "://" .. os.getenv("SERVER_DOMAIN") -- not empty skynet_proof means this is a skylink v2 request -- so we should replace the Skynet-Proof header with the one diff --git a/docker/nginx/conf.d/server/server.api b/docker/nginx/conf.d/server/server.api index f56661b0..15ee50e1 100644 --- a/docker/nginx/conf.d/server/server.api +++ b/docker/nginx/conf.d/server/server.api @@ -276,8 +276,8 @@ location /skynet/tus { # extract skylink from base64 encoded upload metadata and assign to a proper header header_filter_by_lua_block { - ngx.header["Skynet-Portal-Api"] = "https://" .. os.getenv("PORTAL_DOMAIN") - ngx.header["Skynet-Server-Api"] = "https://" .. os.getenv("SERVER_DOMAIN") + ngx.header["Skynet-Portal-Api"] = ngx.var.scheme .. "://" .. os.getenv("PORTAL_DOMAIN") + ngx.header["Skynet-Server-Api"] = ngx.var.scheme .. "://" .. os.getenv("SERVER_DOMAIN") if ngx.header["Upload-Metadata"] then local encodedSkylink = string.match(ngx.header["Upload-Metadata"], "Skylink ([^,?]+)") @@ -311,8 +311,8 @@ location /skynet/metadata { include /etc/nginx/conf.d/include/portal-access-check; header_filter_by_lua_block { - ngx.header["Skynet-Portal-Api"] = "https://" .. os.getenv("PORTAL_DOMAIN") - ngx.header["Skynet-Server-Api"] = "https://" .. os.getenv("SERVER_DOMAIN") + ngx.header["Skynet-Portal-Api"] = ngx.var.scheme .. "://" .. os.getenv("PORTAL_DOMAIN") + ngx.header["Skynet-Server-Api"] = ngx.var.scheme .. "://" .. os.getenv("SERVER_DOMAIN") } proxy_set_header User-Agent: Sia-Agent; @@ -324,8 +324,8 @@ location /skynet/resolve { include /etc/nginx/conf.d/include/portal-access-check; header_filter_by_lua_block { - ngx.header["Skynet-Portal-Api"] = "https://" .. os.getenv("PORTAL_DOMAIN") - ngx.header["Skynet-Server-Api"] = "https://" .. os.getenv("SERVER_DOMAIN") + ngx.header["Skynet-Portal-Api"] = ngx.var.scheme .. "://" .. os.getenv("PORTAL_DOMAIN") + ngx.header["Skynet-Server-Api"] = ngx.var.scheme .. "://" .. os.getenv("SERVER_DOMAIN") } proxy_set_header User-Agent: Sia-Agent; diff --git a/docker/nginx/nginx.conf b/docker/nginx/nginx.conf index 795753fc..f67438e5 100644 --- a/docker/nginx/nginx.conf +++ b/docker/nginx/nginx.conf @@ -95,8 +95,8 @@ http { # include skynet-portal-api and skynet-server-api header on every request header_filter_by_lua_block { - ngx.header["Skynet-Portal-Api"] = "https://" .. os.getenv("PORTAL_DOMAIN") - ngx.header["Skynet-Server-Api"] = "https://" .. os.getenv("SERVER_DOMAIN") + ngx.header["Skynet-Portal-Api"] = ngx.var.scheme .. "://" .. os.getenv("PORTAL_DOMAIN") + ngx.header["Skynet-Server-Api"] = ngx.var.scheme .. "://" .. os.getenv("SERVER_DOMAIN") } # ratelimit specified IPs