[英]Containerized Nginx reverse proxy returning a 502 Bad Gateway
我正在尝试使用 Nginx 反向代理公开公开 Ombi。 Nginx 和 Ombi 都在 Ubuntu 22 主机上的容器中运行。 打开 http://hostname:3579(3579 是它使用的端口)工作正常,如果我在我的路由器中打开 3579,那么http://MYDOMAIN.dev:3579工作。 但是,如果我尝试连接到https://ombi.MYDOMAIN.dev ,使用下面的配置只会返回 502 Bad Gateway。
Docker-compose.yaml:
services:
ombi:
image: lscr.io/linuxserver/ombi:latest
container_name: ombi
environment:
- PUID=1004
- PGID=1004
- TZ=America/Los_Angeles
# - BASE_URL=/ombi #optional
volumes:
- /mnt/vault/data/ombi/config:/config
ports:
- 3579:3579
restart: unless-stopped
nginx:
image: lscr.io/linuxserver/nginx:latest
container_name: nginx
environment:
- PUID=1000
- PGID=1000
- TZ=America/Los_Angeles
volumes:
- /mnt/vault/data/nginx:/config
- /mnt/vault/data/nginx/certbot/www:/var/www/certbot/:ro
ports:
- 80:80
- 443:443
restart: unless-stopped
Nginx-base.conf
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name ombi.MYDOMAIN.dev;
location / {
proxy_pass http://localhost:3579;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
# Added the below per the advice of the following Stack Overflow
# https://stackoverflow.com/questions/47091356/docker-nginx-reverse-proxy-gives-502-bad-gateway
proxy_buffering off;
proxy_buffer_size 16k;
proxy_busy_buffers_size 24k;
proxy_buffers 64 4k; }
# This allows access to the actual api
location /api {
proxy_pass http://localhost:3579;
}
# This allows access to the documentation for the api
location /swagger {
proxy_pass http://localhost:3579;
}
}
SSL.conf
注意:/config/keys/ 是一个混淆,但 Nginx 可以找到密钥,我已经通过 certbot 注册了适当的域。
ssl_certificate /config/keys/fullchain.pem;
ssl_certificate_key /config/keys/privkey.pem;
ssl_session_timeout 1d;
ssl_session_cache shared:MozSSL:10m;
ssl_dhparam /config/dhparams.pem;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;
ssl_prefer_server_ciphers off;
# OCSP stapling
ssl_stapling on;
ssl_stapling_verify on;
也许最令人困惑的是,我在日志中没有看到任何内容。 当我运行docker logs nginx
时,我只得到系统启动日志,当我检查 Ombi UI 中的日志时,它没有提到任何关于失败连接的信息。 我不知道如何解决这个问题。
我在这里尝试了很多变体,包括 (a) 打开/关闭 Ombi 的 base_url 和 (b) 将反向代理设置为 URI 路径,即https://MYDOMAIN.dev/ombi 。 任何能帮助我解决这个问题的人都会赢得我无尽的感激。
好吧,我在这里发帖几分钟后就明白了。 我认为问题在于localhost
对容器的意义与对主机服务器的意义不同。 我修复了这个问题,将localhost
替换为主机的 IP 地址,一切都开始工作了。
我还通过指定上游来源简化了事情。 conf 文件现在看起来像这样:
upstream ombiserver {
server 192.168.4.119:3579;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name ombi.jsmg.dev;
location / {
proxy_pass http://ombiserver;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_buffering off; # for a single server setup (SSL termination of Varnish), where no caching is done in NGINX itself
proxy_buffer_size 16k; # should be enough for most PHP websites, or adjust as above
proxy_busy_buffers_size 24k; # essentially, proxy_buffer_size + 2 small buffers of 4k
proxy_buffers 64 4k; # should be enough for most PHP websites, adjust as above to get an accurate value
}
# This allows access to the actual api
location /api {
proxy_pass http://ombiserver;
}
# This allows access to the documentation for the api
location /swagger {
proxy_pass http://ombiserver;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.