【发布时间】:2019-02-13 17:11:01
【问题描述】:
编辑:我检查了一下,似乎 azure 提供了一个默认的网桥,因此 localhost 解决方案可以正常工作。
我运行两个容器 docker-compose NGINX + Gunicorn&Flask,我想将 NGINX 设置为应用程序的反向代理。我试图让它作为 CLI 在 AZURE 云上运行,但我的 Nginx 无法找到来自应用程序的上游。在我的本地机器上,我在 nginx 配置中获得了这个指定容器名称和相关的暴露端口,这在云上似乎不起作用。
我尝试将 proxy_pass 更改为 localhost(相同端口),但在这种情况下,即使在我的本地计算机上也无法正常工作,返回 502 Bad Gateway 错误。无论如何,我都可以通过浏览器或任何其他方法向应用程序发送请求。 Nginx 与 supervisord 一起运行。 Gunicorn 使用 1 个工作线程 (gthread) 和 4 个不同的线程运行。
这里是我的 nginx.conf(包含在内的那个):
server {
listen 80;
location / {
try_files $uri @proxy_to_app;
}
location @proxy_to_app {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_redirect off;
proxy_pass http://mycontainer:5000;
# proxy_pass http://localhost:5000;
}
}
这里是主要的:
user nginx;
worker_processes 1;
error_log /app/logs/nginx_error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$proxy_add_x_forwarded_for - $remote_user [$time_local] '
'"$request" $status $body_bytes_sent "$http_referer" '
'"$http_user_agent"' ;
access_log /app/logs/nginx_access.log main;
sendfile on;
keepalive_timeout 65;
include /etc/nginx/conf.d/*.conf;
}
daemon off;
【问题讨论】: