无法从 Django Docker 实例内部访问项目绝对网址



我有一个从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?

最新更新