上游过早关闭的连接

时间:2019-04-29 18:58:08

标签: django docker nginx docker-compose gunicorn

我正在尝试使用配置了gunicorn和nginx的django应用程序进行docker化。我正在这里(http://pawamoy.github.io/2018/02/01/docker-compose-django-postgres-nginx.html)进行学习。

然后,当我尝试做 from boto3.session import Session s = Session() regions = s.get_available_regions('rds') print("regions:", regions) $ python3 regions.py regions: ['ap-northeast-1', 'ap-northeast-2', 'ap-south-1', 'ap-southeast-1', 'ap-southeast-2', 'ca-central-1', 'eu-central-1', 'eu-west-1', 'eu-west-2', 'eu-west-3', 'sa-east-1', 'us-east-1', 'us-east-2', 'us-west-1', 'us-west-2'] 时,我得到以下信息。

docker-compose up --build

在网络上,我会收到502 Bad Gateway。

因此,当我查看错误日志时,这就是我得到的。

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

这是我的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

这是我的nginx的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

我尝试弄乱# 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;。似乎也不起作用。

非常感谢有人可以帮助我。谢谢!

0 个答案:

没有答案