Cloudflare 模板又坏了

这是一个与 Issue with Cloudflare template 类似的问题,但这次 Cloudflare 似乎移除了 IPv4 列表末尾的换行符,导致出现以下输出(已添加注释以标出问题所在):

set_real_ip_from 173.245.48.0/20;
set_real_ip_from 103.21.244.0/22;
set_real_ip_from 103.22.200.0/22;
set_real_ip_from 103.31.4.0/22;
set_real_ip_from 141.101.64.0/18;
set_real_ip_from 108.162.192.0/18;
set_real_ip_from 190.93.240.0/20;
set_real_ip_from 188.114.96.0/20;
set_real_ip_from 197.234.240.0/22;
set_real_ip_from 198.41.128.0/17;
set_real_ip_from 162.158.0.0/15;
set_real_ip_from 104.16.0.0/13;
set_real_ip_from 104.24.0.0/14;
set_real_ip_from 172.64.0.0/13;
set_real_ip_from 131.0.72.0/222400:cb00::/32;  # 问题在此处
set_real_ip_from 2606:4700::/32;
set_real_ip_from 2803:f800::/32;
set_real_ip_from 2405:b500::/32;
set_real_ip_from 2405:8100::/32;
set_real_ip_from 2a06:98c0::/29;
set_real_ip_from 2c0f:f248::/32;

我当前使用的版本是 f568633bf060c18cc0866b4018842ce9ec9da33a(最新的 main 分支)。

下面是一个快速演示命令,无论是否有末尾换行符都能正常工作。它不包含原始脚本中的转义处理,因此需要根据实际情况进行调整。

{ wget https://www.cloudflare.com/ips-v4/ -O - && echo && wget https://www.cloudflare.com/ips-v6/ -O -; } | sed '/^$/d; s/.*/set_real_ip_from &;/'
4 个赞

将模板脚本的第一部分更改为以下内容可解决该问题,并正确处理多余的换行符:

#!/bin/bash -e
# 下载 CloudFlare IP 列表
wget https://www.cloudflare.com/ips-v4/ -O - > /tmp/cloudflare-ips
echo >> /tmp/cloudflare-ips
wget https://www.cloudflare.com/ips-v6/ -O - >> /tmp/cloudflare-ips
# 转换为 nginx 命令并为 sed 追加命令中的包含进行转义
CONTENTS=$(</tmp/cloudflare-ips sed '/^$/d; s/^.*/set_real_ip_from &;/' | tr '\n' '\\' | sed 's/\\/\\n/g')
3 个赞

PR: Fix line break handling in Cloudflare template by Zenexer · Pull Request #558 · discourse/discourse_docker · GitHub

6 个赞

这个问题也与上述情况有关吗?@AntiMetaman

我一直在迁移和多次更换 Droplet,但重建后仍无法解决 502 错误。更多详情见:https://meta.discourse.org/t/discourse-updated-from-admin-not-working-after-rebuild-fatal-error-site-does-not-load-anymore-after-rebuild/200443

这个问题大概何时能修复?请在修复后告知我们,以便我们再次尝试重建,避免再次因 502 错误导致崩溃。@Zenexer

1 个赞

感谢你的 PR @Zenexer!已合并!

6 个赞

此主题已在 17 小时后自动关闭,不再允许新回复。