我有一个从 Cookiecutter Django 开始的项目,我目前正在添加 WeasyPrint 以将一些视图作为 PDF 文件提供。这在开发中运行良好。Cookiecutter Django 使用 Caddy 作为 HTTP 服务器。由于无法从 Django docker 实例内部通过其绝对 URL 访问文件,因此我在生产时遇到错误。
从 Django docker 实例内部,这不起作用:
$ curl https://myowndomain.com
curl: (7) Failed to connect to myowndomain.com port 443: Connection timed out
但这确实:
$ curl https://www.google.com
从 Django docker 实例外部,两个 curl 命令都可以正常工作。
我的球童档案:
myowndomain.com {
proxy / django:5000 {
header_upstream Host {host}
header_upstream X-Real-IP {remote}
header_upstream X-Forwarded-Proto {scheme}
except /media
transparent
}
log stdout
errors stdout
gzip
header / {
# Don't show Caddy/Gunicorn as server header.
-Server
# Enable HTTP Strict Transport Security (HSTS) to force clients to always connect via HTTPS (do not use if only testing)
Strict-Transport-Security "max-age=63072000; includeSubDomains; preload"
# Only send Referer header to same origin.
# Django CSRF protection is incompatible with referrer policy set to none.
Referrer-Policy "same-origin"
# Enable cross-site filter (XSS) and tell browser to block detected attacks.
X-XSS-Protection "1; mode=block"
# Prevent some browsers from MIME-sniffing a response away from the declared Content-Type
X-Content-Type-Options "nosniff"
}
}
有什么我需要设置的吗?我错过了什么吗?