Ale*_*exW 6 django nginx amazon-web-services
我正在尝试使用Nginx,unicorn和Django在AWS中设置ECS集群。
我已将docker-compose.yml转换为ECS任务,但想知道如何将nginx配置放入容器中?
这是我在json中的任务
我已经为文件创建了一些挂载点,但是不确定如何在此处获取配置。当我从本地服务器运行docker时,nginx配置文件对于撰写文件而言是本地的,显然在aws中不是吗?
如何通过ecs将nginx配置放入contains?
{
"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"
}
Run Code Online (Sandbox Code Playgroud)
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;
}
Run Code Online (Sandbox Code Playgroud)
据我所知(截至撰写本文时),除了使用环境变量外,没有“直接”方式将配置注入到ECS中的容器中。
尽管如此,您还是可以执行以下操作:
使用AWS CLI从S3获取nginx配置。
将诸如etcd或Consul之类的分布式键值存储部署到您的ECS集群,然后存储并从中检索所需的所有配置。这些工具通常用于共享配置和服务发现。如果您打算将ECS用于您环境中的所有内容,那么这可能是个好主意。例如,关于nginx,您可以设置nginx + consul +注册器+ consul模板,以通过在Consul中更新nginx配置自动在容器内重新加载nginx配置。这是一个例子。
好吧,只是说...我希望有一天AWS 可以在Kubernetes上提供诸如ConfigMap和Secrets之类的东西。在Kubernetes中,就是这样简单:
将Nginx配置添加到Kubernetes集群中: kubectl create configmap nginx-configmap --from-file=nginx.conf
在Pod定义(如“ ECS任务定义”)中定义希望Kubernetes将配置注入到容器中:
volumeMounts:
- name: nginx-config-volume
mountPath: /etc/nginx
...
volumes:
- name: nginx-config-volume
configMap:
name: nginx-configmap
就是这样!
| 归档时间: |
|
| 查看次数: |
2677 次 |
| 最近记录: |