程序问答   发布时间:2022-06-01  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了带有 AWS ECS 错误的 Django 和 Nginx Docker 容器大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决带有 AWS ECS 错误的 Django 和 Nginx Docker 容器?

开发过程中遇到带有 AWS ECS 错误的 Django 和 Nginx Docker 容器的问题如何解决?下面主要结合日常开发的经验,给出你关于带有 AWS ECS 错误的 Django 和 Nginx Docker 容器的解决方法建议,希望对你解决带有 AWS ECS 错误的 Django 和 Nginx Docker 容器有所启发或帮助;

我目前正在使用 terraform 和 AWS ECS 构建一个项目,其中包含两个容器:Django App 和 Nginx(用于托管静态文件)。目前效果很好;但是,我在 Nginx 的日志中收到一个错误(使用 ClouDWatch Logs)说,

CommandError: You must set setTings.ALLOWED_HOSTS if DEBUG is false.

我知道这与 Django 的 ALLOWED_HOSTS 有关,因为我的 DEBUGfalse 文件中设置为 setTings.py,但我觉得一切都应该正常工作。这是我的 setTings.py 为 ALLOWED_HOSTS 准备的:

ALLOWED_HOSTS = os.getenv('ALLOWED_HOSTS','').split()

从这里开始,我的任务定义文件名为 container-def.Json 以在 AWS ECS 中完成工作:

[
  {
    "name": "django-app","image": "${django_docker_imagE}","cpu": 10,"memory": 256,"memoryReservation": 128,"links": [],"essential": true,"portMapPings": [
      {
        "hostPort": 0,"containerPort": 8000,"protocol": "tcp"
      }
    ],"command": ["gunicorn","-w","3","-b",":8000","project.wsgi:application"],"environment": [
      {
        "name": "RDS_db_name","value": "${rds_db_name}"
      },{
        "name": "RDS_USERname","value": "${rds_usernamE}"
      },{
        "name": "RDS@R_262_3988@","value": "${rds@R_262_3988@}"
      },{
        "name": "RDS_PORT","value": "5432"
      },{
        "name": "ALLOWED_HOSTS","value": "${allowed_hosts}"
      }
    ],"mountPoints": [
      {
        "containerPath": "/usr/src/app/staticfiles","sourceVolume": "static_volume"
      }
    ],"logConfiguration": {
      "logDriver": "awslogs","options": {
        "awslogs-group" : "/ecs/frontend-container","awslogs-region": "us-east-1"
      }
    }
  },{
    "name": "Nginx","image": "${ngnix_docker_imagE}","memory": 128,"links": ["django-app"],"containerPort": 80,"options": {
        "awslogs-group": "/ecs/Nginx","awslogs-region": "us-east-1"
      }
    }
  }
]

我的 var.tf 文件是这样的

####### input URL of ALLOWED_HOSTS in Django's setTings ############
variable "allowed_hosts" {
  description = "Domain name for allowed hosts"
  default     = ".example.org"
}

最后,我在 terraform 的数据模板中调用所有这些变量:

### Here lIEs the container-deFinition.Json file to input what each container's parameters
### must have.
data "template_file" "ecs-containers" {
    template = file("container-deFinitions/container-def.Json")

    vars = {
        django_docker_image = var.django_docker_image
        ngnix_docker_image  = var.ngnix_docker_image
        rds_db_name         = var.rds_db_name
        rds_username        = var.rds_username
        rds@R_262_3988@        = var.rds@R_262_3988@
        allowed_hosts       = var.allowed_hosts
    }
}

如果您对此有任何反馈,我将不胜感激。我知道我几乎可以解决这个问题。谢谢大家。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

大佬总结

以上是大佬教程为你收集整理的带有 AWS ECS 错误的 Django 和 Nginx Docker 容器全部内容,希望文章能够帮你解决带有 AWS ECS 错误的 Django 和 Nginx Docker 容器所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。