使用docker compose将nginx.conf负载平衡更正为uvicorn FastAPI

使用docker compose将nginx.conf负载平衡更正为uvicorn FastAPI,nginx,docker-compose,load-balancing,reverse-proxy,fastapi,Nginx,Docker Compose,Load Balancing,Reverse Proxy,Fastapi,我想使用nginx作为复制副本的负载平衡器,但我无法让它工作。我读到uvicorn也可以做到这一点,但nginx可以很好地处理负载平衡 我犯了一个错误 host not found in upstream "inconnect1:5001" docker-compose.yml version: "3" networks: proxy-tier: external: name: nginx-proxy services: inconnect1: im

我想使用nginx作为复制副本的负载平衡器,但我无法让它工作。我读到uvicorn也可以做到这一点,但nginx可以很好地处理负载平衡

我犯了一个错误

host not found in upstream "inconnect1:5001"
docker-compose.yml

version: "3"

networks:
  proxy-tier:
    external:
      name: nginx-proxy

services:

  inconnect1: 
    image: inconnect:0.1
    container_name: inconnect1
    environment:
      - PORT=5001
    volumes:
      - ./inconnect/app:/app
    ports:
      - 5001:5001

  nginx: 
    image: jwilder/nginx-proxy
    container_name: nginx
    ports:
      - 80:80
      - 443:443
    volumes:
      - /var/run/docker.sock:/tmp/docker.sock:ro
      - ./letsencrypt/certs:/etc/nginx/certs:ro
      - ./nginx/nginx.conf:/etc/nginx/nginx.conf
    networks:
      - proxy-tier
    restart: always
    deploy:
      mode: replicated
      replicas: 1
nginx.conf

worker_processes 1;

events { worker_connections 1024; }

http {

sendfile on;

upstream restapis {
server inconnect:5001;
}

server {
listen 80;

location / {
  proxy_set_header Host $http_host;
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  proxy_set_header X-Forwarded-Proto $scheme;
  proxy_redirect off;
  proxy_buffering off;
  proxy_pass http://restapis;
}

location /static {
  # path for static files
  root /path/to/app/static;
}
}
 }

作为nginx.conf文件:

服务器连接:5001
应该是连接1:5001中的
服务器

在docker compose中,文件应该使用从nginx容器到
inconnect1
应用程序的
链接。(删除nginx容器上的网络)

或在1个网络上使用:


谢谢但是,nginx.conf还不能用于SSL,可以修改吗?
    image: jwilder/nginx-proxy
    container_name: nginx
    ports:
      - 80:80
      - 443:443
    volumes:
      - /var/run/docker.sock:/tmp/docker.sock:ro
      - ./letsencrypt/certs:/etc/nginx/certs:ro
      - ./nginx/nginx.conf:/etc/nginx/nginx.conf
    links:
      - "inconnect1:inconnect1"
    restart: always
    deploy:
      mode: replicated
      replicas: 1

networks:
  proxy-tier:
    driver: bridge

services:

  inconnect1: 
    image: inconnect:0.1
    container_name: inconnect1
    environment:
      - PORT=5001
    volumes:
      - ./inconnect/app:/app
    ports:
      - 5001:5001
    networks:
      - proxy-tier

  nginx: 
    image: jwilder/nginx-proxy
    container_name: nginx
    ports:
      - 80:80
      - 443:443
    volumes:
      - /var/run/docker.sock:/tmp/docker.sock:ro
      - ./letsencrypt/certs:/etc/nginx/certs:ro
      - ./nginx/nginx.conf:/etc/nginx/nginx.conf
    networks:
      - proxy-tier
    restart: always
    deploy:
      mode: replicated
      replicas: 1