Nginx 问题,停止和启动应用时出现 "502 Bad Gateway"

当我执行 ./launcher stop app 然后执行 ./launcher start app 时,网站显示 502 Bad Gateway。我不知道问题出在哪里,我尝试重建但没有成功。

请建议如何解决这个问题。

可以分享一下重建日志吗?

root@amsaal:/var/discourse# ./launcher logs app
检测到 x86_64 架构。
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
正在清理过时的 PID 文件
run-parts: executing /etc/runit/1.d/copy-env
run-parts: executing /etc/runit/1.d/letsencrypt
[Mon 15 Apr 2024 10:12:06 AM UTC] 域名未更改。
[Mon 15 Apr 2024 10:12:06 AM UTC] 跳过,下次续订时间为:2024-06-12T11:28:31Z
[Mon 15 Apr 2024 10:12:06 AM UTC] 添加 '--force' 以强制续订。
[Mon 15 Apr 2024 10:12:07 AM UTC] 将密钥安装到:/shared/ssl/amsaal.net.key
[Mon 15 Apr 2024 10:12:07 AM UTC] 将完整链安装到:/shared/ssl/amsaal.net.cer
[Mon 15 Apr 2024 10:12:07 AM UTC] 运行重载命令:sv reload nginx
warning: nginx: 无法打开 supervise/ok:文件不存在
[Mon 15 Apr 2024 10:12:07 AM UTC] 重新加载错误:
[Mon 15 Apr 2024 10:12:07 AM UTC] 域名未更改。
[Mon 15 Apr 2024 10:12:07 AM UTC] 跳过,下次续订时间为:2024-06-12T11:28:38Z
[Mon 15 Apr 2024 10:12:07 AM UTC] 添加 '--force' 以强制续订。
[Mon 15 Apr 2024 10:12:08 AM UTC] 将密钥安装到:/shared/ssl/amsaal.net_ecc.key
[Mon 15 Apr 2024 10:12:08 AM UTC] 将完整链安装到:/shared/ssl/amsaal.net_ecc.cer
[Mon 15 Apr 2024 10:12:08 AM UTC] 运行重载命令:sv reload nginx
warning: nginx: 无法打开 supervise/ok:文件不存在
[Mon 15 Apr 2024 10:12:08 AM UTC] 重新加载错误:
已启动 runsvdir,PID 为 537
ok: run: redis: (pid 550) 0s
ok: run: postgres: (pid 551) 0s
nginx: [warn] "listen ... http2" 指令已弃用,请在 /etc/nginx/conf.d/discourse.conf:60 中使用 "http2" 指令
supervisor pid: 545 unicorn pid: 577
root@amsaal:/var/discourse#

那不是我的意思,你能运行 ./launcher rebuild app,然后分享该命令的输出吗?(另外,请将输出放在代码围栏中,这样可以使主题更易于阅读)

这样重建会更容易,因为它会将 stdout 记录到一个文件中

./launcher rebuild app >> rebuild.log
1 个赞

如果希望每次重建都有不同的文件:

./launcher rebuild app > "rebuild-$(date -Imin).log" 2>&1

启动容器后需要一两分钟才能开始提供服务。您是否尝试过在访问网站之前等待几分钟?

1 个赞
检测到 x86_64 架构。
正在确保启动器是最新的
启动器是最新的
正在停止旧容器
app
2.0.20231218-0429:正在从 discourse/base 拉取
摘要:sha256:468f70b9bb4c6d0c6c2bbb3efc1a5e12d145eae57bdb6946b7fe5558beb52dc1
状态:镜像已是最新 discourse/base:2.0.20231218-0429
docker.io/discourse/base:2.0.20231218-0429
/usr/local/lib/ruby/gems/3.2.0/gems/pups-1.2.1/lib/pups.rb
/usr/local/bin/pups --stdin
97:C 2024年4月15日 18:52:04.329 # oO0OoO0OoO0Oo Redis 正在启动 oO0OoO0OoO0Oo
97:C 2024年4月15日 18:52:04.329 # Redis 版本=7.0.7, 位数=64, 提交=00000000, 修改=0, pid=97, 刚刚启动
97:C 2024年4月15日 18:52:04.330 # 配置已加载
97:M 2024年4月15日 18:52:04.331 * 单调时钟:POSIX clock_gettime
97:M 2024年4月15日 18:52:04.336 * 运行模式=standalone, 端口=6379。
97:M 2024年4月15日 18:52:04.336 # 服务器已初始化
97:M 2024年4月15日 18:52:04.337 * 加载由版本 7.0.7 生成的 RDB
97:M 2024年4月15日 18:52:04.337 * RDB 年龄 31 秒
97:M 2024年4月15日 18:52:04.337 * 创建时的 RDB 内存使用量 23.25 Mb
97:M 2024年4月15日 18:52:04.451 * RDB 加载完成,已加载键:1351,已过期键:5。
97:M 2024年4月15日 18:52:04.461 * DB 从磁盘加载:0.124 秒
97:M 2024年4月15日 18:52:04.461 * 已准备好接受连接
3507:C 2024年4月15日 18:58:01.238 # oO0OoO0OoO0Oo Redis 正在启动 oO0OoO0OoO0Oo
3507:C 2024年4月15日 18:58:01.238 # Redis 版本=7.0.7, 位数=64, 提交=00000000, 修改=0, pid=3507, 刚刚启动
3507:C 2024年4月15日 18:58:01.238 # 配置已加载
3507:M 2024年4月15日 18:58:01.239 * 单调时钟:POSIX clock_gettime
3507:M 2024年4月15日 18:58:01.240 # 警告:无法创建服务器 TCP 监听套接字 *:6379:bind:地址已在使用中
3507:M 2024年4月15日 18:58:01.240 # 端口 6379 (TCP) 监听失败,中止。
97:M 2024年4月15日 18:58:27.220 * 300 秒内 100 次更改。正在保存...
97:M 2024年4月15日 18:58:27.223 * 后台保存由 pid 3555 启动
3555:C 2024年4月15日 18:58:30.967 * DB 已在磁盘上保存
3555:C 2024年4月15日 18:58:30.969 * RDB 的 Fork CoW:当前 1 MB,峰值 1 MB,平均 1 MB
97:M 2024年4月15日 18:58:31.058 * 后台保存已成功终止
97:M 2024年4月15日 19:03:32.047 * 300 秒内 100 次更改。正在保存...
97:M 2024年4月15日 19:03:32.063 * 后台保存由 pid 3634 启动
3634:C 2024年4月15日 19:03:37.774 * DB 已在磁盘上保存
3634:C 2024年4月15日 19:03:37.777 * RDB 的 Fork CoW:当前 1 MB,峰值 1 MB,平均 1 MB
97:M 2024年4月15日 19:03:37.828 * 后台保存已成功终止
97:signal-handler (1713208309) 收到 SIGTERM,正在调度关闭...
97:M 2024年4月15日 19:11:49.130 # 用户请求关闭...
97:M 2024年4月15日 19:11:49.131 * 正在退出前保存最终 RDB 快照。
97:M 2024年4月15日 19:11:52.592 * DB 已在磁盘上保存
97:M 2024年4月15日 19:11:52.593 # Redis 已准备好退出,再见...
sha256:066d1fc0bf450b6f9043e13960cafef6b7751d92f0d89cc4e0865208293ce2e2
58661874f252e2e9dac3955608dbbe90e60f020a4d307d2818e7f991d39f8010
正在移除旧容器
app

ea032a7acab7743f4ef8de3b9a536da0dbbf36b8c9dd5b2a9add0cfb01286e5d

是的,在重建过程完成后 30 秒后,网站无法正常工作,出现 502 网关错误,然后我执行了 /launch restart app with launch start app 命令,它就可以工作了。

所以可能有什么问题。

这……感觉像是不完整的日志。它真的就到这里结束了,还是只是暂停了很长时间?如果是后者,那么你可能需要更多的内存/交换空间。

尝试等待 60 秒。

1 个赞

可能需要暂停,或者需要很长时间,大约 30 分钟才能完成重建,我认为是只有 2 GB 的内存导致速度变慢,但目前我没有内存问题。它只是正常运行缓慢,根据规格不应超过 1-2 分钟。

我的以下 VPS 规格。

CPU:AMD EPYC 7551P 32 核处理器,2000 MHz
内存:2 GB
SSD:60 GB

如果容器没有运行,你就不会收到 502 错误。如果你再等一会儿,网站就会开始正常运行。

并不是停止和启动起了什么作用,只是你在重启时等了很长时间。

在容器启动期间出现 502 错误是预期之中的。你没有遇到问题。

1 个赞

老实说,这并不算太不寻常,重建速度不快,尤其是在……

……你没有很多内存的情况下。

如今,Discourse通常建议至少有4GB的总内存(内存和交换空间)。

在通过管理界面更新 discourse 时,我收到了不兼容的警告

warning Resolution field "unset-value@2.0.1" is incompatible with requested version "unset-value@^1.0.0"
[3/5] Fetching packages...
warning Pattern ["wrap-ansi-cjs@npm: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@^7.0.0"]. This could result in non-deterministic behavior, skipping.
[4/5] Linking dependencies...
warning "@discourse/lint-configs > eslint-plugin-ember > ember-eslint-parser@0.3.8" has unmet peer dependency "@typescript-eslint/parser@^6.15.0".
warning "> @glint/environment-ember-loose@1.4.0" has unmet peer dependency "@glimmer/component@^1.1.2".
warning "> discourse-markdown-it@1.0.0" has unmet peer dependency "xss@*".
warning "workspace-aggregator-e69f39ff-3f17-47f3-9e20-638bb7914a45 > discourse > @uppy/aws-s3@3.0.6" has incorrect peer dependency "@uppy/core@^3.1.2".
warning "workspace-aggregator-e69f39ff-3f17-47f3-9e20-638bb7914a45 > discourse > @uppy/aws-s3-multipart@3.1.3" has incorrect peer dependency "@uppy/core@^3.1.2".
warning "workspace-aggregator-e69f39ff-3f17-47f3-9e20-638bb7914a45 > discourse > @uppy/xhr-upload@3.1.1" has incorrect peer dependency "@uppy/core@^3.1.2".
warning "workspace-aggregator-e69f39ff-3f17-47f3-9e20-638bb7914a45 > discourse-plugins > ember-this-fallback@0.4.0" has unmet peer dependency "ember-source@^3.28.11 || ^4.0.0".
warning "workspace-aggregator-e69f39ff-3f17-47f3-9e20-638bb7914a45 > admin > ember-source > router_js@8.0.3" has unmet peer dependency "rsvp@^4.8.5".
warning "workspace-aggregator-e69f39ff-3f17-47f3-9e20-638bb7914a45 > discourse > @uppy/aws-s3 > @uppy/xhr-upload@3.3.0" has incorrect peer dependency "@uppy/core@^3.2.1".

这些可以安全地忽略,不会阻止 Discourse 进行重建。