gpt4 book ai didi

docker - Docker + Nginx允许来自外部docker的上游gunicorn

转载 作者:行者123 更新时间:2023-12-02 19:17:03 28 4
gpt4 key购买 nike

我有一个运行Nginx的docker-compose容器,我想与在同一台机器上的docker外部运行的Flask + Gunicorn一起使用。当我同时在Docker中运行时,一切都可以通过docker-compose.yml links正常运行,但是当我在Flask之外运行Gunicorn + Docker时,出现了我要解决的错误。如何解决此错误?
我得到的错误是

2020/07/17 03:24:49 [error] 38#38: *1 connect() failed (111: Connection refused) while connecting to upstream, client: *.*.*.*, server: website.com, request: "GET / HTTP/2.0", upstream: "http://127.0.0.1:5000/", host: "website.com"
我正在通过 gunicorn运行 gunicorn --bind 0.0.0.0:5000 wsgi:app我的Nginx website.conf
upstream hello_server {
#server 127.0.0.1:5000;
server 0.0.0.0:5000;
}

server {
listen 80;
# ...

location ^~ /static/ {
# Path of your static files
root /var/www;
}

location / {
proxy_pass_header Server;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Scheme $scheme;
proxy_pass http://frontends;
}
}
}
我的 docker-compose.yml
version: '3'

services:

web:
image: nginx:latest
ports:
- 80:80/tcp
- 443:443/tcp

最佳答案

您可以使用HOST IP,例如,上游运行在5000端口上,只需将frontend指向HOST IP,例如192.168.0.1

 server {
listen 80;
location ^~ /static/ {
# Path of your static files
root /var/www;
}

location / {
proxy_pass_header Server;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Scheme $scheme;
proxy_pass http://192.168.0.1:5000;
}
}
或带有上游变量
upstream gunicornapp {
server 192.168.43.84:3000;
}

server {
listen 80;
location ^~ /static/ {
# Path of your static files
root /var/www;
}

location / {
proxy_pass_header Server;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Scheme $scheme;
proxy_pass http://gunicornapp;
}
}

关于docker - Docker + Nginx允许来自外部docker的上游gunicorn,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62946747/

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