This commit is contained in:
Dallas Lu 2026-06-05 13:06:08 +08:00
parent cb97070442
commit f04c14116d
No known key found for this signature in database
3 changed files with 19 additions and 3 deletions

View file

@ -0,0 +1,9 @@
set $root_domain "";
if ($server_name ~* ^www\.(?<apex_domain>.+)$) {
set $root_domain $apex_domain;
}
if ($host = $root_domain) {
return 307 $scheme://$server_name$request_uri;
}

View file

@ -0,0 +1,3 @@
if ($host = www.$server_name) {
return 307 $scheme://$server_name$request_uri;
}

View file

@ -19,21 +19,25 @@ $serverSnippetConfig = @(
"}" "}"
) -join "\n" ) -join "\n"
$serverSnippetConfigShell = $serverSnippetConfig -replace "\\", "\\\\" -replace "'", "'\"'\"'" -replace "`n", "\\n" $serverSnippetConfigShell = $serverSnippetConfig -replace "`n", "\\n"
$containerCommand = @( $containerCommand = @(
"set -eu" "set -eu"
"apk add --no-cache openssl >/dev/null" "apk add --no-cache openssl >/dev/null"
"mkdir -p /etc/nginx/snippets/cert /etc/ssl/certimate /tmp/nginx-kit/snippets/cert" "mkdir -p /etc/nginx/snippets/cert /etc/ssl/certimate /tmp/nginx-kit/snippets/cert /tmp/nginx-kit/examples/snippets/cert"
"openssl req -x509 -nodes -newkey rsa:2048 -keyout /etc/ssl/certimate/example.com.key -out /etc/ssl/certimate/example.com.crt -subj '/CN=example.com' -days 1 >/dev/null 2>&1" "openssl req -x509 -nodes -newkey rsa:2048 -keyout /etc/ssl/certimate/example.com.key -out /etc/ssl/certimate/example.com.crt -subj '/CN=example.com' -days 1 >/dev/null 2>&1"
"cp /etc/nginx/kit/templates/cert/example.com.conf /etc/nginx/snippets/cert/mydomain.com.conf" "cp /etc/nginx/kit/templates/cert/example.com.conf /etc/nginx/snippets/cert/mydomain.com.conf"
"cp /etc/nginx/kit/templates/cert/example.com.conf /tmp/nginx-kit/snippets/cert/mydomain.com.conf" "cp /etc/nginx/kit/templates/cert/example.com.conf /tmp/nginx-kit/snippets/cert/mydomain.com.conf"
"cp /etc/nginx/kit/templates/cert/example.com.conf /tmp/nginx-kit/examples/snippets/cert/mydomain.com.conf"
"ln -s /etc/nginx/kit /tmp/nginx-kit/kit" "ln -s /etc/nginx/kit /tmp/nginx-kit/kit"
"mkdir -p /tmp/nginx-kit/examples"
"ln -s /etc/nginx/kit /tmp/nginx-kit/examples/kit"
"cp /etc/nginx/kit/examples/reverse-proxy.nginx.conf /tmp/nginx-kit/examples/reverse-proxy.nginx.conf"
"printf '%b' '$serverSnippetConfigShell' > /tmp/nginx-kit/server-snippet.nginx.conf" "printf '%b' '$serverSnippetConfigShell' > /tmp/nginx-kit/server-snippet.nginx.conf"
"echo 'Validating examples/example.com.conf'" "echo 'Validating examples/example.com.conf'"
"nginx -t -c /tmp/nginx-kit/server-snippet.nginx.conf" "nginx -t -c /tmp/nginx-kit/server-snippet.nginx.conf"
"echo 'Validating examples/reverse-proxy.nginx.conf'" "echo 'Validating examples/reverse-proxy.nginx.conf'"
"nginx -t -c /etc/nginx/kit/examples/reverse-proxy.nginx.conf" "nginx -t -c /tmp/nginx-kit/examples/reverse-proxy.nginx.conf"
) -join "; " ) -join "; "
docker run --rm ` docker run --rm `