1
0
mirror of https://github.com/thib8956/nginx-proxy synced 2025-07-03 07:15:46 +00:00

Merge pull request #1737 from junderw/fix-redirect

feat: redirect non-GET methods using 308 instead of 301
This commit is contained in:
Nicolas Duchon
2025-01-18 22:03:27 +01:00
committed by GitHub
6 changed files with 111 additions and 5 deletions

View File

@ -32,6 +32,7 @@
{{- $_ := set $config "enable_http3" ($globals.Env.ENABLE_HTTP3 | default "false") }}
{{- $_ := set $config "enable_http_on_missing_cert" ($globals.Env.ENABLE_HTTP_ON_MISSING_CERT | default "true") }}
{{- $_ := set $config "https_method" ($globals.Env.HTTPS_METHOD | default "redirect") }}
{{- $_ := set $config "non_get_redirect" ($globals.Env.NON_GET_REDIRECT | default "301") }}
{{- $_ := set $config "default_host" $globals.Env.DEFAULT_HOST }}
{{- $_ := set $config "resolvers" $globals.Env.RESOLVERS }}
{{- /* LOG_JSON is a shorthand that sets logging defaults to JSON format */}}
@ -736,8 +737,11 @@ proxy_set_header Proxy "";
{{- if and $https_method_disable_http (not $cert_ok) $enable_http_on_missing_cert }}
{{- $https_method = "noredirect" }}
{{- end }}
{{- $non_get_redirect := groupByLabel $vhost_containers "com.github.nginx-proxy.nginx-proxy.non-get-redirect" | keys | first | default $globals.config.non_get_redirect }}
{{- $http2_enabled := groupByLabel $vhost_containers "com.github.nginx-proxy.nginx-proxy.http2.enable" | keys | first | default $globals.config.enable_http2 | parseBool }}
{{- $http3_enabled := groupByLabel $vhost_containers "com.github.nginx-proxy.nginx-proxy.http3.enable" | keys | first | default $globals.config.enable_http3 | parseBool }}
{{- $acme_http_challenge := groupByKeys $vhost_containers "Env.ACME_HTTP_CHALLENGE_LOCATION" | first | default $globals.config.acme_http_challenge }}
{{- $acme_http_challenge_legacy := eq $acme_http_challenge "legacy" }}
{{- $acme_http_challenge_enabled := false }}
@ -764,6 +768,7 @@ proxy_set_header Proxy "";
"default" $default
"hsts" $hsts
"https_method" $https_method
"non_get_redirect" $non_get_redirect
"http2_enabled" $http2_enabled
"http3_enabled" $http3_enabled
"is_regexp" $is_regexp
@ -904,11 +909,14 @@ server {
{{- end }}
location / {
{{- if eq $globals.config.external_https_port "443" }}
return 301 https://$host$request_uri;
{{- else }}
return 301 https://$host:{{ $globals.config.external_https_port }}$request_uri;
{{- end }}
{{- $redirect_uri := "https://$host$request_uri" }}
{{- if ne $globals.config.external_https_port "443" }}
{{- $redirect_uri = printf "https://$host:%s$request_uri" $globals.config.external_https_port }}
{{- end}}
if ($request_method ~ (OPTIONS|POST|PUT|PATCH|DELETE)) {
return {{ $vhost.non_get_redirect }} {{ $redirect_uri }};
}
return 301 {{ $redirect_uri }};
}
}
{{- end }}