【发布时间】:2019-04-01 16:28:14
【问题描述】:
我有这个docker-compose.yml 文件:
version: '2'
services:
nginx:
image: nginx:latest
container_name: nz01
ports:
- "8001:8000"
volumes:
- ./src:/src
- ./config/nginx:/etc/nginx/conf.d
depends_on:
- web
web:
build: .
container_name: dz01
depends_on:
- db
volumes:
- ./src:/src
expose:
- "8000"
db:
image: postgres:latest
container_name: pz01
ports:
- "5433:5432"
volumes:
- postgres_database:/var/lib/postgresql/data:Z
volumes:
postgres_database:
external: true
还有这个 dockerfile:
FROM python:3.5
ENV PYTHONUNBUFFERED 1
RUN mkdir /src
RUN mkdir /static
WORKDIR /src
ADD ./src /src
RUN pip install -r requirements.pip
CMD python manage.py collectstatic --no-input;python manage.py migrate; gunicorn computationalMarketing.wsgi -b 0.0.0.0:8000
web 和 postgres 服务器不返回错误日志,仅当我运行 docker-compose build 和 docker-compose up -d 时返回成功。
此时三个容器正在运行,但是当我转到浏览器并导航到:localhost:8001 时,它不起作用。
它显示“连接已重新启动”错误消息。
尽管如此,Web 服务器仍然没有返回任何错误,所以我想我的 Django 应用程序中的所有内容都已正确配置。我真的相信这个问题与Nginx 有关,因为当我查看Nginx log(使用运动学)时,它仍然是空的。
为什么 Nginx 不监听连接?
提示: 这个错误发生在一个新项目中。我试图了解我是否有任何问题,我正在运行一个旧项目并且它运行良好。我试图将工作项目复制到我的新文件夹中并删除所有现有容器,然后尝试在新文件夹中运行这个旧项目,结果令人惊讶。它现在不起作用,尽管它是在另一个文件夹中工作的项目的精确副本......
编辑
在我的仓库中,我有一个带有 helloworld.conf 文件的 config/nginx 文件夹:
upstream web {
ip_hash;
server web:8000;
}
server {
location /static/ {
autoindex on;
alias /src/static/;
}
location / {
proxy_pass http://web/;
}
listen 8001;
server_name localhost;
}
仍然出现同样的错误...我没有看到任何日志错误。
Django 容器日志
Operations to perform:
Apply all migrations: admin, auth, contenttypes, sessions
Running migrations:
No migrations to apply.
[2018-11-05 13:00:09 +0000] [8] [INFO] Starting gunicorn 19.7.1
[2018-11-05 13:00:09 +0000] [8] [INFO] Listening at: http://0.0.0.0:8000 (8)
[2018-11-05 13:00:09 +0000] [8] [INFO] Using worker: sync
[2018-11-05 13:00:09 +0000] [11] [INFO] Booting worker with pid: 11
【问题讨论】:
-
默认的 nginx 镜像监听 80 端口。调整你的端口映射到它。
-
@KlausD。你的意思是在 docker-compose.yml 文件中吗?那么在 nginx 端口映射中正确设置是 8001:80 呢?
-
你能把你的 nginx conf.d 放进去吗?
-
我们需要 nginx 配置来帮助
-
@RaoslawSzamszur 抱歉,我忘记了。现在您可以在原帖中找到。
标签: python django docker nginx