django - 我在使用 docker nginx 和 gunicorn 部署我的 django 项目时遇到问题
问题描述
如果我在服务器端运行了我的容器并且一切正常,为了在浏览器上访问路由,我应该将带有域的 nginx 容器的 ip 放在 etc/host 中还是必须在没有它的情况下工作?我的 nginx.config
server {
listen 80;
server_name my_domain;
root /code/;
error_log /var/log/nginx/new_error.log debug;
location / {
proxy_pass http://web:8000/;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_redirect off;
}
location /staticfiles/ {
alias /code/staticfiles/;
}
location /mediafiles/ {
alias /code/mediafiles/;
}
}
web 是我运行 gunicorn 的 docker 容器
解决方案
如果您的 nginx 容器具有使用该标志公开的端口,-p <host_port>:<container_port>
您可以访问 nginx 服务,在您的 /etc/hosts 文件中添加指向本地主机 ip 的域,但是如果您没有使用此标志,则需要指向该 ip你的 nginx 容器。有什么区别?...当您公开端口时,您甚至可以在部署容器的主机之外使用该服务。
我希望能帮助你。
推荐阅读
- drupal - 如何在drupal 8中使用自定义块中的字段
- ios - 在 Swift 中检测 2 个 UIImageView 的交集
- github-api - 通过 GitHub api 获取提交的行数
- vba - 变量不变
- php - 我的 PHP 表单发送数据但 sql 显示所有列零记录
- android - 在主线程外运行时对 Cloud Firestore 进行同步调用
- c# - 替换方法不适用于 C# 中的转义字符 '\xA0'
- javascript - 如何获取密钥并将其附加到 json 文件中的下一个值?
- python - 为多处理序列化对象很慢——有没有办法只序列化一次?
- python - Cloud Foundry 上的 Flask 应用程序 - 命令“python setup.py egg_info”失败,错误代码为 1