我有一个使用 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"
}
}
有什么我需要设置的吗?我错过了什么吗?
可能在开发中它在端口 80 上使用 http,在生产中它在端口 443 上使用 https。
在 docker-compose.yml 中或当您调用 docker 时,您是否公开端口 443?
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)