相关疑难解决方法(0)

使用nginx作为反向代理时,连接到上游时连接被拒绝

设置如下:我有一个0.0.0.0:8000可以通过浏览器访问的Gunicorn/Django应用程序.为了提供静态文件,我将nginx作为反向代理运行./etc/nginx/nginx.conf配置为转发请求,如下所示:

server {
    location /static/ {
        alias /data/www/;
    }


    # Proxying the connections
    location / {
        proxy_set_header   Host $host;
        proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;

        proxy_redirect     off;
        proxy_pass         http://0.0.0.0:8000;
    }
}
Run Code Online (Sandbox Code Playgroud)

我的docker-compose.yml文件如下:

version: '3.3'

services:
  web:
    restart: always
    build: ./web
    expose:
      - "8000"
    ports:
      - "8000:8000"
    volumes:
      - staticdata:/usr/src/app/static_files
    command: gunicorn wsgi:application --workers 2 --bind 0.0.0.0:8000
    depends_on:
      - postgres

  nginx:
    restart: always
    build: ./nginx
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - staticdata:/data/www
    depends_on:
      - web

  postgres:
    image: …
Run Code Online (Sandbox Code Playgroud)

nginx gunicorn docker

3
推荐指数
1
解决办法
6134
查看次数

标签 统计

docker ×1

gunicorn ×1

nginx ×1