【发布时间】:2022-01-03 17:41:57
【问题描述】:
我尝试构建一个 Django / Gunicorn / Nginx 配置以在 AWS 上运行。数据库容器单独运行。但是,在执行 docker-compose 构建步骤时,nginx 步骤失败了。文件如下所示:
dockerfile.prod:
version: '3'
services:
web:
build:
context: .
dockerfile: Dockerfile.prod
container_name: app
command: gunicorn The6ix.wsgi:application --bind 0.0.0.0:8000
volumes:
- static_volume:/home/app/web/staticfiles
networks:
- dbnet
expose:
- 8000
environment:
aws_access_key_id: ${aws_access_key_id}
aws_secret_access_key: ${aws_secret_access_key}
nginx:
build: ./nginx
ports:
- 1337:80
volumes:
- static_volume:/home/app/web/staticfiles
- media_volume:/home/app/web/mediafiles
depends_on:
- web
volumes:
static_volume:
media_volume:
networks:
dbnet:
external: true
我的 nginx Dockerfile(在 ./nginx 文件夹中):
FROM nginx:1.21-alpine
RUN rm /etc/nginx/conf.d/default.conf
COPY nginx.conf /etc/nginx/conf.d
我的 nginx.conf 文件(在 ./nginx 文件夹中):
upstream The6ix {
server web:8000;
}
server {
listen 80;
location / {
proxy_pass http://The6ix;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_redirect off;
}
location /static/ {
alias /home/app/web/staticfiles/;
}
location /media/ {
alias /home/app/web/mediafiles/;
}
我的 nginx 容器的错误日志如下:
/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
10-listen-on-ipv6-by-default.sh: info: /etc/nginx/conf.d/default.conf is not a file or does not exist
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
/docker-entrypoint.sh: Configuration complete; ready for start up
2022/01/03 17:33:59 [emerg] 1#1: host not found in upstream "web:8000" in /etc/nginx/conf.d/nginx.conf:2
nginx: [emerg] host not found in upstream "web:8000" in /etc/nginx/conf.d/nginx.conf:2
一些帖子提到使用 .yaml 文件中的卷创建步骤是罪魁祸首。但是有没有更好的方法来排序以启用 nginx 的正确运行?
【问题讨论】:
标签: docker nginx docker-compose