이 문제에 대해 좀 고전하고 있습니다. 아니, 꽤 많이 고전하고 있죠.
사이트 중 하나에 CDN을 추가하는 실험을 하기로 결정했습니다.
문서를 읽은 후, Fastly가 권장하는 기준(그리고 그렇게 하라는 일반적인 조언)을 충족시키기 위해 현재 최상위 도메인(apex domain)에서 서브도메인으로 사이트를 이동하는 것이 더 낫다는 것을 깨달았습니다.
그래서 "음, 이건 쉬울 텐데, 전에 해본 적 있으니까…"라고 생각했습니다. 정말이었나요? 
해당 사이트는 https://starzen.space 입니다.
저희는 이 가이드를 사용하여 이번 주말에 사이트를 https://www.starzen.space 로 이동했습니다.
모두 순조롭게 진행되었지만, 물론 이 사이트를 통해 지금까지 확보한 소수의 사용자들을 고려해야 하므로 리다이렉트를 추가하고 싶었습니다.
제 이해로는 원래 링크에도 인증서가 발급되어야 하므로, 이 가이드(예전에는 훨씬 더 복잡했었나요?)를 따라 app.yml에 다음 내용을 추가했습니다:
hooks:
after_ssl:
- replace:
filename: "/etc/runit/1.d/letsencrypt"
from: /--keylength/
to: "-d starzen.space --keylength"
- replace:
filename: "/etc/nginx/conf.d/discourse.conf"
from: /return 301 https.+/
to: |
return 301 https://$host$request_uri;
after_web_config:
- replace:
filename: /etc/nginx/nginx.conf
from: /sendfile.+on;/
to: |
server_names_hash_bucket_size 64;
sendfile on;
- file:
path: /etc/nginx/conf.d/discourse_redirect_1.conf
contents: |
server {
listen 80;
listen 443 ssl;
server_name starzen.space;
return 301 $scheme://www.starzen.space$request_uri;
}
재빌드 시 모든 것이 정상적으로 진행되는 것처럼 보입니다.
그러나 브라우저로 https://starzen.space 에 접속을 시도하면 다음과 같은 화면이 나타납니다:
curl을 실행하면:
blah discourse % curl https://starzen.space
curl: (60) SSL: no alternative certificate subject name matches target host name 'starzen.space'
More details here: https://curl.se/docs/sslcerts.html
curl failed to verify the legitimacy of the server and therefore could not
establish a secure connection to it. To learn more about this situation and
how to fix it, please visit the web page mentioned above.
인증서가 문제인 것 같다고 확신합니다. 왜냐하면 동일한 명령을 보안 무시 모드(insecure mode)로 실행하면 다음과 같은 결과가 나오기 때문입니다:
blah discourse % curl -k https://starzen.space
<html>
<head><title>301 Moved Permanently</title></head>
<body>
<center><h1>301 Moved Permanently</h1></center>
<hr><center>nginx/1.21.6</center>
</body>
</html>
이것이 제가 원하는 결과라고 생각합니다.
수정된 스크립트 파일이 올바른 것 같습니다. 현재 가지고 있는 내용은 다음과 같습니다:
root@starship-enterprise:/etc/runit/1.d# cat letsencrypt
#!/bin/bash
/usr/sbin/nginx -c /etc/nginx/letsencrypt.conf
issue_cert() {
LE_WORKING_DIR="${LETSENCRYPT_DIR}" /shared/letsencrypt/acme.sh --issue $2 -d www.starzen.space -d starzen.space --keylength $1 -w /var/www/discourse/public
}
cert_exists() {
[[ "$(cd /shared/letsencrypt/www.starzen.space$1 && openssl verify -CAfile <(openssl x509 -in ca.cer) fullchain.cer | grep "OK")" ]]
}
########################################################
# RSA cert
########################################################
issue_cert "4096"
if ! cert_exists ""; then
# Try to issue the cert again if something goes wrong
issue_cert "4096" "--force"
fi
<SNIP>
컨테이너 내부에서 명령줄을 통해 이 스크립트를 직접 실행해 보기도 했습니다. 실행하기 전에 이중 도메인에 대한 올바른 명령이 실행되도록 대상 디렉터리에서 모든 인증서 파일을 백업 디렉터리로 이동했습니다:
root@starship-enterprise:/etc/runit/1.d# ./letsencrypt
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()
[Sun 25 Sep 2022 05:50:04 PM UTC] Using CA: https://acme-v02.api.letsencrypt.org/directory
[Sun 25 Sep 2022 05:50:04 PM UTC] Creating domain key
[Sun 25 Sep 2022 05:50:05 PM UTC] The domain key is here: /shared/letsencrypt/www.starzen.space/www.starzen.space.key
[Sun 25 Sep 2022 05:50:05 PM UTC] Multi domain='DNS:www.starzen.space,DNS:starzen.space'
[Sun 25 Sep 2022 05:50:05 PM UTC] Getting domain auth token for each domain
[Sun 25 Sep 2022 05:50:08 PM UTC] Getting webroot for domain='www.starzen.space'
[Sun 25 Sep 2022 05:50:08 PM UTC] Getting webroot for domain='starzen.space'
[Sun 25 Sep 2022 05:50:08 PM UTC] www.starzen.space is already verified, skip http-01.
[Sun 25 Sep 2022 05:50:08 PM UTC] Verifying: starzen.space
[Sun 25 Sep 2022 05:50:12 PM UTC] Pending
[Sun 25 Sep 2022 05:50:15 PM UTC] Success
[Sun 25 Sep 2022 05:50:15 PM UTC] Verify finished, start to sign.
[Sun 25 Sep 2022 05:50:15 PM UTC] Lets finalize the order.
[Sun 25 Sep 2022 05:50:15 PM UTC] Le_OrderFinalize='https://acme-v02.api.letsencrypt.org/acme/finalize/590255196/128806215177'
[Sun 25 Sep 2022 05:50:16 PM UTC] Downloading cert.
[Sun 25 Sep 2022 05:50:16 PM UTC] Le_LinkCert='https://acme-v02.api.letsencrypt.org/acme/cert/03ff6b1b76f8516165032c6c2e02205a529b'
[Sun 25 Sep 2022 05:50:17 PM UTC] Cert success.
-----BEGIN CERTIFICATE-----
Lotsofcrazytext
-----END CERTIFICATE-----
[Sun 25 Sep 2022 05:50:17 PM UTC] Your cert is in /shared/letsencrypt/www.starzen.space/www.starzen.space.cer
[Sun 25 Sep 2022 05:50:17 PM UTC] Your cert key is in /shared/letsencrypt/www.starzen.space/www.starzen.space.key
[Sun 25 Sep 2022 05:50:17 PM UTC] The intermediate CA cert is in /shared/letsencrypt/www.starzen.space/ca.cer
[Sun 25 Sep 2022 05:50:17 PM UTC] And the full chain certs is there: /shared/letsencrypt/www.starzen.space/fullchain.cer
[Sun 25 Sep 2022 05:50:17 PM UTC] Installing key to:/shared/ssl/www.starzen.space.key
[Sun 25 Sep 2022 05:50:17 PM UTC] Installing full chain to:/shared/ssl/www.starzen.space.cer
[Sun 25 Sep 2022 05:50:17 PM UTC] Run reload cmd: sv reload nginx
ok: run: nginx: (pid 579) 35281s
[Sun 25 Sep 2022 05:50:17 PM UTC] Reload success
[Sun 25 Sep 2022 05:50:18 PM UTC] Domains not changed.
[Sun 25 Sep 2022 05:50:18 PM UTC] Skip, Next renewal time is: Wed 23 Nov 2022 10:01:01 AM UTC
[Sun 25 Sep 2022 05:50:18 PM UTC] Add '--force' to force to renew.
[Sun 25 Sep 2022 05:50:18 PM UTC] Installing key to:/shared/ssl/www.starzen.space_ecc.key
[Sun 25 Sep 2022 05:50:18 PM UTC] Installing full chain to:/shared/ssl/www.starzen.space_ecc.cer
[Sun 25 Sep 2022 05:50:18 PM UTC] Run reload cmd: sv reload nginx
ok: run: nginx: (pid 579) 35282s
[Sun 25 Sep 2022 05:50:18 PM UTC] Reload success
거의 성공적으로 끝났습니다!!! 이제 curl은 훨씬 더 친절해져서 리다이렉트를 반환해 줍니다:
blah discourse % curl https://starzen.space
<html>
<head><title>301 Moved Permanently</title></head>
<body>
<center><h1>301 Moved Permanently</h1></center>
<hr><center>nginx/1.21.6</center>
</body>
</html>
그리고 Firefox 및 Chrome에서 https://starzen.space 는 이제 정상적으로 작동하여 올바른 서브도메인으로 리다이렉트됩니다. 하지만 여전히 Safari에서는 그 끔찍한 오류 화면이 나타납니다. 무슨 일이죠? 사이트 재시작도 하고 이 사이트의 캐시도 비웠는데 말이죠:
브라우저에서 인증서를 확인해 보니 다음과 같습니다: