我正在运行traefik来在docker容器中提供python django应用程序。该应用程序运行没有问题通过https或http。在一个非特定的时间(一小时后),traefik日志说" 502 Bad Gateway "我的nginx和uwsgi日志没有说什么。 " docker restart djangoapp"短时间内修复了问题。
互联网 - > traefik - > nginx - > uwsgi - > djangoapp
debug = true
defaultEntryPoints = ["http", "https"]
# Access log
[traefikLog]
filePath = "/var/log/traefik/traefik.log"
format = "json"
[accessLog]
filePath = "/var/log/traefik/access.log"
format = "json"
[web]
address = ":8080"
[web.auth.basic]
users = ["admin:XXX/"]
[entryPoints]
[entryPoints.http]
address = ":80"
[entryPoints.https]
address = ":443"
[entryPoints.https.tls]
[[entryPoints.https.tls.certificates]]
certFile = "/etc/ssl/traefik/cert-register.stupa.pem"
keyFile = "/etc/ssl/traefik/key-register.stupa.key"
version: '2'
services:
frontproxy:
image: traefik
container_name: frontproxy
command: --api --docker --docker.domain=docker.localhost
ports:
- "80:80"
- "8080:8080"
- "443:443"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- $PWD/traefik.toml:/traefik.toml
- /srv/ssl/certs:/etc/ssl/traefik
- /srv/frontproxy/logs:/var/log/traefik
networks:
default:
external:
name: frontproxy
version: '3'
networks:
helfertoolnet:
frontproxy:
external: true
volumes:
postgresVolume:
services:
helfertool_app:
image: helfertool
hostname: helfertool_app
command: [/usr/bin/supervisord]
container_name: helfertool_app
volumes:
- /srv/helfertool/conf/nginx/helfertool.conf:/etc/nginx/sites-enabled/helfertool.conf
- /srv/helfertool/conf/helfertool/settings_local.py:/app/helfertool/helfertool/settings_local.py
- /srv/helfertool/conf/nginx/logs:/var/log/nginx
- /srv/helfertool/conf/supervisor:/etc/supervisor/conf.d
- /srv/helfertool/conf/uwsgi:/etc/uwsgi/apps-enabled
depends_on:
- "helfertool_rabbitmq"
- "helfertool_db"
labels:
- traefik.backend=helfertool
- traefik.frontend.rule=Host:XXX
- traefik.docker.network=frontproxy
- traefik.port=80
- traefik.frontend.entryPoints=http,https
networks:
- frontproxy
- helfertoolnet
helfertool_rabbitmq:
image: rabbitmq:3
hostname: helfertool_rabbitmq
container_name: helfertool_rabbitmq
environment:
- RABBITMQ_DEFAULT_USER=XXX
- RABBITMQ_DEFAULT_PASS=XXX
- RABBITMQ_DEFAULT_VHOST=XXX
networks:
- helfertoolnet
helfertool_db:
image: postgres
command: postgres -c listen_addresses='*'
hostname: helfertool_db
container_name: helfertool_db
environment:
- POSTGRES_PASSWORD=XXX
- POSTGRES_USER=XXX
volumes:
# Persist the data between container invocations
- postgresVolume:/var/lib/postgresql/data
networks:
- helfertoolnet
{"BackendAddr":"172.18.0.7:80",
"BackendName":"backend-helfertool",
"BackendURL":
{"Scheme":"http",
"Opaque":"",
"User":null,
"Host":"172.18.0.7:80",
"Path":"",
"RawPath":"",
"ForceQuery":false,
"RawQuery":"",
"Fragment":""},
"ClientAddr":"141.60.38.168:60979",
"ClientHost":"141.60.38.168",
"ClientPort":"60979",
"ClientUsername":"-"
,"DownstreamContentSize":11,
"DownstreamStatus":502,
"DownstreamStatusLine":"502 Bad Gateway",
"Duration":1074690,
"FrontendName":"Host-register-stupa-fh-rosenheimde-0",
"OriginContentSize":11,
"OriginDuration":855550,
"OriginStatus":502,
"OriginStatusLine":"502 Bad Gateway",
"Overhead":219140,
"RequestAddr":"register.stupa.fh-rosenheim.de",
"RequestContentSize":0,
"RequestCount":27132,
"RequestHost":"register.stupa.fh-rosenheim.de",
"RequestLine":"GET / HTTP/1.1",
"RequestMethod":"GET",
"RequestPath":"/",
"RequestPort":"-",
"RequestProtocol":"HTTP/1.1",
"RetryAttempts":0,
"StartLocal":"2018-05-25T12:55:18.619598232Z",
"StartUTC":"2018-05-25T12:55:18.619598232Z",
"level":"info",
"msg":"",
"request_Accept":"text/html,application/xhtml+xml,
application/xml;q=0.9,*/*;q=0.8",
"request_Accept-Encoding":"gzip,deflate",
"request_Accept-Language":"de,en-US;q=0.7,en;q=0.3",
"request_Cache-Control":"max-age=0",
"request_Connection":"keep-alive",
"request_Cookie":"csrftoken=awELtrVSPImPNZFNph6SYs0eJuAZcjIzX462ykgUip1hQVQagaaKQxZhFUbzUrS5;
sessionid=4bcrynx0qyu2bam1nf8eewiurv0vtn5a",
"request_Referer":"http://register.stupa.fh-rosenheim.de/weinfest2018/",
"request_Upgrade-Insecure-Requests":"1",
"request_User-Agent":"Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Firefox/52.0","time":"2018-05-25T12:55:18Z"}
谢谢:)
答案 0 :(得分:0)
可能是您的uswgi容器重新启动并在docker中获得新的IP地址的情况,所以nginx无法解析它。