使用 Let's Encrypt 设置多个域名 / 重定向

哦,哇,终于成功了:

true | openssl s_client -connect www.starzen.space:443 2>/dev/null \
| openssl x509 -noout -text \
| perl -l -0777 -ne '@names=/\\bDNS:([^\\s,]+)/g; print join("\n", sort @names);'
starzen.space
www.starzen.space

我注释掉了 letsencrypt 脚本中的 if 语句,以强制重新颁发。当然,这不是一个“工厂”解决方案。

然而,这表明问题出在“状态”而不是提供的选项上。

看起来当前的脚本可能会根据先前的状态被卡住,但如果你强制重新颁发,你就可以修复它。

不过,现在我拥有了一个可用的 apex 域名!:tada:

4 个赞

这是标准安装的一部分。请参阅 User Guide — Certbot 5.1.0 documentation 并向下滚动到 管理证书,以及紧随其后,重新创建和更新现有证书

这些命令将在您最初运行 Certbot 的位置运行。

1 个赞

我有一个标准的安装,并且没有使用 certbot。服务器级别没有,即使我说先 ./launcher enter app 也没有。

我估计是因为 acme.sh 导致它丢失了。

3 个赞

我似乎遇到了类似的问题。我曾以为是因为我使用了子子域名 (Let's Encrypt with sub-subdomain?),但我也尝试过使用常规子域名,但新站点的证书仍然无法生成。

我正在尝试弄清楚你是如何破解它使其生效的,但我似乎无法理解 :grimacing:

你是怎么让它对你起作用的?

如果是这个原因,你注释掉了哪一个 if 语句?

另外,你对可能导致这个新问题的原因有什么想法吗?

1 个赞

我的问题与我的多站点配置中的过期域名有关:

2 个赞

@Brahn

感谢您最近更新的说明。

在将我的根域名指向子域名后,我看到了一个证书错误。我已经将我的 app.yml 文件更新为您想要测试的较新版本,问题已解决。 :slightly_smiling_face:

4 个赞

我刚刚也必须实施这个,在更改域名并导致重定向失败之后。

我已经对 wiki 做了一些小的修改,删除了旧的说明并更正了新说明中的空格。

但是,到目前为止似乎还没有奏效。我怀疑我需要强制颁发新证书。有人能指导我如何轻松做到这一点吗?

我几乎可以肯定我刚刚进行了一次重建。可能是有些东西又变了。你还有旧证书吗?主机名是什么?如果你愿意,可以私信我。

谢谢 Jay - forum.hinz.org.nz 是旧域名(ehealthforum.nz 是新域名)。

我进行了一次重建(仅限 web_only,作为 2-container),但这似乎并没有解决问题。

您也更改了主机名?您是否更改了 Discourse 的域名或重命名了它

非请自来的建议:最佳实践似乎是使用 www 而不是顶级域名。我使用的浏览器几乎无法分辨 www 是否在那里。

我唯一的猜测是,引号内的尾随空格很重要,而您没有它?

我想我会进入容器并四处查看,尝试像它那样运行 acme 并看看会发生什么;我总是记不起如何做到这一点或在哪里查找 acme 命令;我每次都必须弄清楚,所以我无法告诉您。您也许可以从 docker logs web_only 中看到。

我发誓,当我上次编辑这个的时候,它是有效的。我确实检查了我应用它的站点,它似乎有其额外的有效证书在工作。但可以想象,它可能有一个与现在不同的基础镜像,并且在下次重建时会损坏。

我将尝试在有机会时再次检查一下。也许是下周。

1 个赞

是的,我做了所有这些,而且没有问题。

确实如此,但只有在您计划使用 CDN 或子域时才值得这样做(我不这样做):
https://hostadvice.com/blog/domains/what-is-apex-domain/

我尝试添加了它,但没有效果。

这很有启发性(点击展开)

> root@forumhinz:/var/discourse# docker logs web_only
> run-parts: executing /etc/runit/1.d/00-ensure-links
> run-parts: executing /etc/runit/1.d/00-fix-var-logs
> run-parts: executing /etc/runit/1.d/01-cleanup-web-pids
> run-parts: executing /etc/runit/1.d/anacron
> run-parts: executing /etc/runit/1.d/cleanup-pids
> Cleaning stale PID files
> run-parts: executing /etc/runit/1.d/copy-env
> run-parts: executing /etc/runit/1.d/letsencrypt
> [Sat 9 Sep 08:19:27 UTC 2023] Domains not changed.
> [Sat 9 Sep 08:19:27 UTC 2023] Skip, Next renewal time is: 2023-10-26T08:24:32Z
> [Sat 9 Sep 08:19:27 UTC 2023] Add ‘–force’ to force to renew.
> [Sat 9 Sep 08:19:29 UTC 2023] Installing key to: /shared/ssl/ehealthforum.nz.key
> [Sat 9 Sep 08:19:29 UTC 2023] Installing full chain to: /shared/ssl/ehealthforum.nz.cer
> [Sat 9 Sep 08:19:29 UTC 2023] Run reload cmd: sv reload nginx
> warning: nginx: unable to open supervise/ok: file does not exist
> [Sat 9 Sep 08:19:29 UTC 2023] Reload error for :
> [Sat 9 Sep 08:19:29 UTC 2023] Domains not changed.
> [Sat 9 Sep 08:19:30 UTC 2023] Skip, Next renewal time is: 2023-10-26T08:24:45Z
> [Sat 9 Sep 08:19:30 UTC 2023] Add ‘–force’ to force to renew.
> [Sat 9 Sep 08:19:31 UTC 2023] Installing key to: /shared/ssl/ehealthforum.nz_ecc.key
> [Sat 9 Sep 08:19:31 UTC 2023] Installing full chain to: /shared/ssl/ehealthforum.nz_ecc.cer
> [Sat 9 Sep 08:19:31 UTC 2023] Run reload cmd: sv reload nginx
> warning: nginx: unable to open supervise/ok: file does not exist
> [Sat 9 Sep 08:19:31 UTC 2023] Reload error for :
> Started runsvdir, PID is 570
> supervisor pid: 578 unicorn pid: 590

这似乎意味着如果我找不到强制续订的方法,我将不得不等到 2023-10-26T08:24:00Z 才能解决问题!

我将尝试一些方法 - 祝我好运。

稍后…

成功!

嗯,在尝试了几次启动证书续订但失败后,我最终迁移到了一个新服务器(这本来就已经计划好了)。

出乎意料的是,这完美地续订了证书,使用了 OP 中的设置。真是奇怪。

我不知道将来如何能做得更好。也许提前一两个月建立新域名的 DNS 设置,然后将这些行添加到您的 app.yml 中。

2 个赞

我将此添加到我的 app.yml 文件中,我需要重建吗?还是它会自动生效?
另外在
“from: /-d www.first-domain.com/” 中,我应该放我想重定向的域名还是我的子域名?

1 个赞

是的,app.yml 中的任何更改通常都需要重新构建。

3 个赞

我重建后,我的网站无法访问。我应该再次重建吗?
重建后出现此提示:

"Pups::ExecError: cd /var/www/discourse && su discourse -c 'bundle exec rake themes:update assets:precompile' failed with return #<Process::Status: pid 3575 exit 134>
Location of failure: /usr/local/lib/ruby/gems/3.2.0/gems/pups-1.2.1/lib/pups/exec_command.rb:132:in `spawn'
exec failed with the params {"cd"=>"$home", "hook"=>"assets_precompile", "cmd"=>["su discourse -c 'bundle exec rake themes:update assets:precompile'"]}
bootstrap failed with exit code 134
** FAILED TO BOOTSTRAP ** please scroll up and look for earlier error messages, there may be more than one."
1 个赞

重建过程是否顺利,没有出现任何错误?

2 个赞

请执行此操作,并分享错误消息。

2 个赞
110:M 2023年12月10日 13:32:18.543 # 服务器已初始化
110:M 2023年12月10日 13:32:18.543 # 警告:必须启用内存超额提交!否则,后台保存或复制在内存不足的情况下可能会失败。禁用它也可能在内存未不足的情况下导致失败,请参阅 https://github.com/jemalloc/jemalloc/issues/1328。要解决此问题,请在 /etc/sysctl.conf 中添加“vm.overcommit_memory = 1”,然后重新启动或运行命令“sysctl vm.overcommit_memory=1”使其生效。
110:M 2023年12月10日 13:32:18.544 * 加载由版本 7.0.7 生成的 RDB

我收到了这些警告,不确定它们是否重要。

warning “ > @glint/environment-ember-loose@1.1.0” has unmet peer dependency “@glimmer/component@^1.1.2”。
warning “ > @glint/environment-ember-template-imports@1.1.0” has unmet peer dependency “ember-template-imports@^3.0.0”。
warning Resolution field “unset-value@2.0.1” is incompatible with requested version “unset-value@^1.0.0”
warning Pattern [“wrap-ansi@^7.0.0”] is trying to unpack in the same destination “/home/discourse/.cache/yarn/v6/npm-wrap-ansi-cjs-7.0.0-67e145cff510a6a6984bdf1152911d69d2eb9e43-integrity/node_modules/wrap-ansi-cjs” as pattern [“wrap-ansi-cjs@npm:wrap-ansi@^7.0.0”]. This could result in non-deterministic behavior, skipping.
warning “ > discourse-markdown-it@1.0.0” has unmet peer dependency “xss@*”.
warning “workspace-aggregator-68bace53-129d-4a2d-85c3-4685b91c92ee > discourse > @ember/legacy-built-in-components@0.5.0” has incorrect peer dependency “ember-source@>= 4.8”.
warning “workspace-aggregator-68bace53-129d-4a2d-85c3-4685b91c92ee > discourse > @uppy/aws-s3@3.0.6” has incorrect peer dependency “@uppy/core@^3.1.2”.
warning “workspace-aggregator-68bace53-129d-4a2d-85c3-4685b91c92ee > discourse > @uppy/aws-s3-multipart@3.1.3” has incorrect peer dependency “@uppy/core@^3.1.2”.
warning “workspace-aggregator-68bace53-129d-4a2d-85c3-4685b91c92ee > discourse > @uppy/xhr-upload@3.1.1” has incorrect peer dependency “@uppy/core@^3.1.2”.
warning “workspace-aggregator-68bace53-129d-4a2d-85c3-4685b91c92ee > discourse-plugins > ember-this-fallback@0.4.0” has unmet peer dependency “ember-source@^3.28.11 || ^4.0.0”.
warning “workspace-aggregator-68bace53-129d-4a2d-85c3-4685b91c92ee > discourse > @uppy/aws-s3 > @uppy/xhr-upload@3.3.0” has incorrect peer dependency “@uppy/core@^3.2.1”.
<--- Last few GCs --->

[3710:0x6291170]   681247 ms: Scavenge 942.0 (1034.0) -> 940.8 (1034.0) MB, 62.9 / 0.0 ms  (average mu = 0.704, current mu = 0.878) allocation failure;
[3710:0x6291170]   681616 ms: Scavenge 942.4 (1034.0) -> 941.4 (1034.0) MB, 18.3 / 0.0 ms  (average mu = 0.704, current mu = 0.878) allocation failure;
[3710:0x6291170]   681911 ms: Scavenge 943.0 (1034.0) -> 942.0 (1038.0) MB, 46.8 / 0.0 ms  (average mu = 0.704, current mu = 0.878) allocation failure;
FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
 1: 0xb83f50 node::Abort() [ember]
 2: 0xa94834  [ember]
 3: 0xd647c0 v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [ember]
 4: 0xd64b67 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [ember]
 5: 0xf42265  [ember]
 6: 0xf5474d v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [ember]
 7: 0xf2ee4e v8::internal::HeapAllocator::AllocateRawWithLightRetrySlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [ember]
 8: 0xf30217 v8::internal::HeapAllocator::AllocateRawWithRetryOrFailSlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [ember]
 9: 0xf113ea v8::internal::Factory::NewFillerObject(int, v8::internal::AllocationAlignment, v8::internal::AllocationType, v8::internal::AllocationOrigin) [ember]
10: 0x12d674f v8::internal::Runtime_AllocateInYoungGeneration(int, unsigned long*, v8::internal::Isolate*) [ember]
11: 0x17035b9  [ember]
Aborted (core dumped)
error Command failed with exit code 134.

我的网站显示

无法访问此网站

forum.mysite.ca拒绝连接。

尝试:

  • 检查连接
  • [检查代理和防火墙]

ERR_CONNECTION_REFUSED

这是我的 app.yml 文件内容

hooks:
  after_code:
    - exec:
        cd: $home/plugins
        cmd:
          - git clone https://github.com/discourse/docker_manager.git
          - git clone https://github.com/discourse/discourse-zoom.git
  after_ssl:
    - replace:
        filename: "/etc/runit/1.d/letsencrypt"
        from: "-d www.mysite.ca/"
        to: "-d www.mysite.ca -d mysite.ca "
## Any custom commands to run after building
1 个赞

您的服务器有多少内存,是否启用了交换空间(请运行 free -h 查看)?

              总计       已用       可用       共享  缓冲/缓存      可用
内存:           957        190        371           3         395        613
交换:          2047         79       1968

您的服务器有 1 GB RAM,并分配了 2 GB 用于交换。奇怪的是,重建过程在此交换容量下会失败。

您可以尝试再次重建。如果失败,您可能需要升级服务器内存(仅用于构建过程,完成后可以降级)。

1 个赞