Я пытаюсь докернизировать мое приложение django с настроенным gunicorn и nginx Я следую этому уроку здесь (http://pawamoy.github.io/2018/02/01/docker-compose-django-postgres-nginx.html), чтобы сделать это.
Впоследствии, когда я пытаюсь сделать docker-compose up --build
, я получаю следующее.
Successfully built 2ba3b610b1c0
Successfully tagged djangotools_iedb_tools:latest
Starting djangotools_iedb_tools_1 ... done
Starting djangotools_nginx_1 ... done
Attaching to djangotools_iedb_tools_1, djangotools_nginx_1
iedb_tools_1 | [2019-04-29 18:37:26 +0000] [1] [INFO] Starting gunicorn 19.9.0
iedb_tools_1 | [2019-04-29 18:37:26 +0000] [1] [INFO] Listening at: http://0.0.0.0:8000 (1)
iedb_tools_1 | [2019-04-29 18:37:26 +0000] [1] [INFO] Using worker: sync
iedb_tools_1 | [2019-04-29 18:37:26 +0000] [10] [INFO] Booting worker with pid: 10
iedb_tools_1 | [2019-04-29 18:38:03 +0000] [1] [CRITICAL] WORKER TIMEOUT (pid:10)
nginx_1 | 2019/04/29 18:38:03 [error] 6#6: *1 upstream prematurely closed connection while reading response header from upstream, client: 172.23.0.1, server: 127.0.0.1, request: "GET / HTTP/1.1", upstream: "http://172.23.0.2:8000/", host: "0.0.0.0:8000"
nginx_1 | 172.23.0.1 - - [29/Apr/2019:18:38:03 +0000] "GET / HTTP/1.1" 502 576 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36" "-"
iedb_tools_1 | [2019-04-29 11:38:03 +0000] [10] [INFO] Worker exiting (pid: 10)
iedb_tools_1 | [2019-04-29 18:38:04 +0000] [39] [INFO] Booting worker with pid: 39
В Интернете я бы получил 502 Bad Gateway.
Итак, когда я посмотрел журналы ошибок, это то, что я получил.
2019/04/29 00:29:43 [error] 93565#93565: *1 connect() to unix:/run/gunicorn.sock failed (111: Connection refused) while connecting to upstream, client: 127.0.0.1, server: 127.0.0.1, request: "GET / HTTP/1.1", upstream: "http://unix:/run/gunicorn.sock:/", host: "0.0.0.0:8000"
2019/04/29 00:51:18 [emerg] 95415#95415: bind() to 0.0.0.0:8000 failed (98: Address already in use)
2019/04/29 00:51:18 [emerg] 95415#95415: bind() to 0.0.0.0:8000 failed (98: Address already in use)
2019/04/29 00:51:18 [emerg] 95415#95415: bind() to 0.0.0.0:8000 failed (98: Address already in use)
2019/04/29 00:51:18 [emerg] 95415#95415: bind() to 0.0.0.0:8000 failed (98: Address already in use)
2019/04/29 00:51:18 [emerg] 95415#95415: bind() to 0.0.0.0:8000 failed (98: Address already in use)
2019/04/29 00:51:18 [emerg] 95415#95415: still could not bind()
2019/04/29 01:08:30 [error] 98516#98516: *1 connect() to unix:/run/gunicorn.sock failed (111: Connection refused) while connecting to upstream, client: 127.0.0.1, server: 127.0.0.1, request: "GET / HTTP/1.1", upstream: "http://unix:/run/gunicorn.sock:/", host: "0.0.0.0:8000"
Это мой docker-compose.yml
version: '3'
services:
iedb_tools:
build: .
volumes:
- .:/src/djangotools/djangotools
networks:
- nginx_network
nginx:
image: nginx:1.13
ports:
- 8000:80
volumes:
- ./config/nginx/conf.d:/etc/nginx/conf.d
depends_on:
- iedb_tools
networks:
- nginx_network
networks:
nginx_network:
driver: bridge
и вот мой local.conf
для nginx.
# Declare upstream server (Gunicorn application)
upstream iedb_server {
server iedb_tools:8000;
}
# Declare main server
server {
listen 80;
server_name localhost;
location / {
# Everthing is passed to Gunicorn
proxy_read_timeout 300s;
proxy_connect_timeout 120s;
proxy_pass http://iedb_server;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_redirect off;
}
}
Я пытался возиться с proxy_read/connect_timeout
, но это не сработало. Я пытался комментировать listen 80 default_server;
и listen [::]:80 ipv6only=on default_server;
из /etc/nginx/sites-availabe/default
. Кажется, тоже не работает.
Очень признателен, что кто-то может мне помочь. Спасибо!