【问题标题】:Docker uWSGI - NGINX: uWSGI ok but NGINX is a 502Docker uWSGI - NGINX:uWSGI ok 但 NGINX 是 502
【发布时间】:2018-11-27 02:20:07
【问题描述】:

我使用 docker compose 配置了我的 django-uwsgi-nginx 和以下文件。

从浏览器“http://127.0.0.1:8000/”工作正常,并为我提供 django 默认页面

从浏览器“http://127.0.0.1:80”抛出 502 Bad Gateway


dravoka-docker.conf

upstream web {
    server 0.0.0.0:8000;
}

server {
    listen 80;
    server_name web;

    location = /favicon.ico { access_log off; log_not_found off; }
    location /static/ {
        alias "/dravoka-static/";
    }

    location / {
        include         uwsgi_params;
        proxy_pass      http://web;
    }
}

nginx/Dockerfile

FROM nginx:latest
RUN echo "---------------------- I AM NGINX --------------------------"
RUN rm /etc/nginx/conf.d/default.conf
ADD sites-enabled/ /etc/nginx/conf.d
RUN nginx -t

web 只是来自“django-admin startproject web”

docker-compose.yaml

version: '3'

services:

  nginx:
    restart: always
    build: ./nginx/
    depends_on:
      - web
    ports:
      - "80:80"

  web:
    build: .
    image: dravoka-image
    ports:
      - "8000:8000"
    volumes:
      - .:/dravoka
    command: uwsgi /dravoka/web/dravoka.ini

Dockerfile

# Ubuntu base image
FROM ubuntu:latest
# Some installs........
EXPOSE 80

【问题讨论】:

  • 终端> nginx_1 | 2018/06/18 11:18:29 [error] 7#7: *1 connect() failed (111: Connection refused) while connection to upstream, client: 172.23.0.1, server: web, request: "GET / HTTP /1.1”,上游:“0.0.0.0:8000”,主机:“127.0.0.1”

标签: docker nginx docker-compose uwsgi


【解决方案1】:

当您从 docker 实例中说时,您是从容器中运行 curl 的??或者您正在本地运行 curl 命令?

如果您是从本地运行它,请将 docker-compose 的 web 服务更新为关注

...
  web:
    build: .
    image: dravoka-image
    expose:
      - "8000:8000"
    volumes:
      - .:/dravoka
    command: uwsgi /dravoka/web/dravoka.ini

然后再试一次。

【讨论】:

  • 当我执行“docker ps -a”时,我有两个容器,我都输入了 'docker exec -it da11eabd1110 bin/bash' 并卷曲
  • 好的,那么您的 docker-compose.yml 中存在一些问题,因为在您的 nginx 配置中,您已经打开了端口 80,但在 Nginx 配置中,您正在监听 8000
  • 好的,我会检查并尝试您的解决方案。当我安装 nginx、uwsgi 而没有使用 shell 脚本编写时,一切正常。
  • 我之前试过这个,但没有任何作用
  • 尝试更新您的上游,而不是 0.0.0.0 使用 web
猜你喜欢
  • 1970-01-01
  • 2015-04-30
  • 1970-01-01
  • 2017-06-23
  • 2016-02-16
  • 2012-07-10
  • 1970-01-01
  • 2019-01-01
  • 1970-01-01
相关资源
最近更新 更多