gpt4 book ai didi

django - 当我使用Nginx和docker-compose时在上游找不到主机

转载 作者:行者123 更新时间:2023-12-02 18:21:42 25 4
gpt4 key购买 nike

这是我的docker-compose.yml文件

我想使Nginx反向代理和Django到Web服务器

我也将每个容器分开

version: '2'

services:
django:
build: ./django
container_name: django

nginx:
restart: always
build: ./nginx
container_name: reversproxy
ports:
- "7891:7891"
depends_on:
- django

而下面是我的nginx.conf

我将uwsgi_pass设置为uwsgicluster,上游设置为django容器

但是nginx容器无法正常工作

nginx:在上游“django:7893”中找不到[emerg]主机
worker_processes 1;

events { worker_connections 1024; }

http {
sendfile on;

upstream uwsgicluster {
server django:7893;
}


server {
listen 7891;

location / {
include /etc/nginx/uwsgi_params;
uwsgi_pass uwsgicluster;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
}
}

}

我该如何解决这个问题?

最佳答案

您应该在docker compose文件中定义links以将django链接到nginx,否则nginx将无法访问django容器。

links

Link to containers in another service. Either specify both the service name and a link alias ("SERVICE:ALIAS"), or just the service name.



Official document explain

关于django - 当我使用Nginx和docker-compose时在上游找不到主机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51434084/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com