【发布时间】:2018-02-18 08:27:53
【问题描述】:
我正在尝试使用 Nginx、unicorn 和 Django 在 AWS 中设置 ECS 集群。
我已将 docker-compose.yml 转换为 ECS 任务,但想知道如何将我的 nginx 配置放入容器中?
这是我在 json 中的任务
我已经为文件创建了一些挂载点,但不确定如何在那里获取配置。 当我从本地服务器运行 docker 时,nginx 配置文件是 compose 文件的本地文件,显然在 aws 中不是?
如何通过 ecs 将 nginx 配置导入到容器中?
{
"containerDefinitions": [
{
"volumesFrom": null,
"memory": 300,
"extraHosts": null,
"dnsServers": null,
"disableNetworking": null,
"dnsSearchDomains": null,
"portMappings": [
{
"containerPort": 8000,
"protocol": "tcp"
}
],
"hostname": null,
"essential": true,
"entryPoint": null,
"mountPoints": [
{
"containerPath": "/static",
"sourceVolume": "_Static",
"readOnly": null
}
],
"name": "it-app",
"ulimits": null,
"dockerSecurityOptions": null,
"environment": null,
"links": null,
"workingDirectory": "/itapp",
"readonlyRootFilesystem": null,
"image": "*****.amazonaws.com/itapp",
"command": [
"bash",
"-c",
"",
"python manage.py collectstatic --noinput && python manage.py makemigrations && python manage.py migrate && gunicorn itapp.wsgi -b 0.0.0.0:8000"
],
"user": null,
"dockerLabels": null,
"logConfiguration": null,
"cpu": 0,
"privileged": null
},
{
"volumesFrom": null,
"memory": 300,
"extraHosts": null,
"dnsServers": null,
"disableNetworking": null,
"dnsSearchDomains": null,
"portMappings": [
{
"hostPort": 80,
"containerPort": 8000,
"protocol": "tcp"
}
],
"hostname": null,
"essential": true,
"entryPoint": null,
"mountPoints": [
{
"containerPath": "/etc/nginx/conf.d",
"sourceVolume": "_ConfigNginx",
"readOnly": null
},
{
"containerPath": "/static",
"sourceVolume": "_Static",
"readOnly": null
}
],
"name": "nginx",
"ulimits": null,
"dockerSecurityOptions": null,
"environment": null,
"links": [
"it-app"
],
"workingDirectory": null,
"readonlyRootFilesystem": null,
"image": "nginx:latest",
"command": null,
"user": null,
"dockerLabels": null,
"logConfiguration": null,
"cpu": 0,
"privileged": null
}
],
"placementConstraints": [],
"volumes": [
{
"host": {
"sourcePath": "./config/nginx"
},
"name": "_ConfigNginx"
},
{
"host": {
"sourcePath": "./static"
},
"name": "_Static"
}
],
"family": "it-app-task",
"networkMode": "bridge"
}
ngnix 配置
upstream web {
ip_hash;
server web:8000;
}
server {
location /static/ {
autoindex on;
alias /static/;
}
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_pass http://web/;
}
listen 8000;
server_name localhost;
}
【问题讨论】:
标签: django amazon-web-services nginx