나에게 가장 쉬웠던 방법은 Discourse의 app.yml에 추가 라벨을 설정하여 Traefik이 X-Forwarded-Proto: https 헤더를 추가하도록 하는 것이었지만, 그 후 nginx가 해당 매개변수를 자체 버전으로 덮어쓰는 문제가 발생했습니다.
그리고 Discourse의 nginx 설정이 여기에 영향을 미칩니다:
여기서 Discourse는 원래 요청에서 프로토콜을 추측하려 합니다(제 환경에서는 Traefik이 전송하는 것이 항상 평문 텍스트이므로 항상 평문이 됩니다). 그리고 나서 그것을 사용하여 여러 번 X-Forwarded-Proto를 설정합니다.
결국, 저는 containers/app.yml을 편집하여 해당 헤더를 https로 하드코딩했습니다:
run:
- exec: echo "Beginning of custom commands"
## If you want to set the 'From' email address for your first registration, uncomment and change:
## After getting the first signup email, re-comment the line. It only needs to run once.
# - exec: rails r "SiteSetting.notification_email='no-reply@forum.cabana.network'"
- replace:
filename: "/etc/nginx/conf.d/discourse.conf"
from: /# attempt to preserve the proto, must be in http context\nmap \$http_x_forwarded_proto \$thescheme {\n default \$scheme;\n "~https\$" https;\n\}/
to: |
# force https scheme so Discourse generates HTTPs links and redirects (ie, `/login`)
- replace:
filename: "/etc/nginx/conf.d/discourse.conf"
from: "$thescheme"
global: "true"
to: "https"
- exec: echo "End of custom commands"
다시 한번 말씀드리자면, force_https 설정이 있다면, 역프록시나 다른 당사자가 처리하든 말든 관계없이 Discourse-rails 앱은 이를 존중해야 한다고 생각합니다.