Todd_S
(Todd S)
1
我正在使用 WP-Discourse 插件暂存 WordPress 和 Discourse 站点(自托管)。
我已成功在两个站点上启用了 HTTP 基本身份验证,以防止它们在上线前被访问(有效阻止了普通公众以及搜索引擎的访问)。
WordPress(为希望实现类似功能的人提供信息)
Discourse
WP-Discourse 插件在 Discourse 服务器上启用基本身份验证之前运行良好。
(编辑)这是 WordPress 端 WP-Discourse 插件日志中的错误:[2025-02-14 18:20:06] connection.INFO: check_connection_status.failed_to_connect {\"error\":\"wpdc_response_error\",\"message\":\"An invalid response was returned from Discourse\",\"http_code\":401,\"http_body\":\"\u003chtml\u003e\\r\\n\u003chead\u003e\u003ctitle\u003e401 Authorization Required\u003c/title\u003e\u003c/head\u003e\\r\\n\u003cbody\u003e\\r\\n\u003ccenter\u003e\u003ch1\u003e401 Authorization Required\u003c/h1\u003e\u003c/center\u003e\\r\\n\u003chr\u003e\u003ccenter\u003enginx\u003c/center\u003e\\r\\n\u003c/body\u003e\\r\\n\u003c/html\u003e\\r\\n\"}
关于如何排除 API 在 Discourse 上需要 HTTP 基本身份验证的任何想法?
谢谢!
pfaffman
(Jay Pfaffman)
2
您真的成功了吗?我不完全确定 Discourse 在基本身份验证下是否能正常工作;我曾尝试过一次但放弃了。它似乎更有可能破坏 wp-discourse(哦,而且我关于这一点是对的!)。如果您成功了,您就不会写这条消息了。
对于 Discourse 暂存站点,我通常只设置“需要登录”,这样可以阻止搜索引擎。有登录名的人仍然可以登录,但这通常是您想要的。
如果您的站点对任何人开放是不可接受的,那么您应该使用防火墙并将访问限制在您的 IP 地址。
您能否告知基本身份验证允许从您的 Discourse 服务器的 IP 访问?也许:Allow access from one IP, require basic auth from all other sources - Traefik v2 - Traefik Labs Community Forum
Todd_S
(Todd S)
3
谢谢,这个线索帮助我解决了问题。这是我的 Discourse 服务器上 app.yml 的更新后的基础身份验证部分(Wordpress 服务器上无需更改):
# 基础身份验证
after_bundle_exec:
- replace:
filename: "/etc/nginx/conf.d/discourse.conf"
from: "# Allow bypass cache from localhost"
to: |
# 允许 WP-Discourse 插件绕过基础身份验证
geo $authentication {
default "您必须提供的凭据。";
127.0.0.1 "off";
151.101.3.55/32 "off";
}
# 允许绕过本地缓存
- replace:
filename: "/etc/nginx/conf.d/discourse.conf"
from: "# auth_basic on"
to: "auth_basic $authentication"
- replace:
filename: "/etc/nginx/conf.d/discourse.conf"
from: "# auth_basic_user_file /etc/nginx/htpasswd"
to: "auth_basic_user_file /etc/nginx/htpasswd"
- replace:
filename: "/etc/nginx/conf.d/discourse.conf"
from: "location = /srv/status {"
to: "location = /srv/status {
auth_basic off;"
- file:
path: "/etc/nginx/htpasswd"
contents: |
alfred:$apr1$jSdLuHyZ$faWxYGjnmLd/zRC6UMsRs1
151.101.3.55 是我的 Wordpress 服务器的(示例)公共 IP 地址。WP-Discourse 现在报告:

2 个赞
system
(system)
关闭
4
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.