docker - 如何使用 swag 反向代理域根目录中的 docker 映像和子域中的另一个映像?
问题描述
我正在使用“linuxserver”的 swag图像来反向代理我的 docker-compose 图像。我想将我的一张图片作为我的域根,另一张作为子域(例如root-image @ mysite.com 和subdomain-image @ staging.mysite.com)。以下是我经历的步骤:
- 将我的域名和子域名重定向到我在 Cloudflare 中的服务器(ping 它们会显示我服务器的 IP,这一步OK!)
- 为 swag 配置了 Cloudflare DNS 配置(这工作正常!)
- 配置 docker-compose 文件:
swag:
image: linuxserver/swag:version-1.14.0
container_name: swag
cap_add:
- NET_ADMIN
environment:
- PUID=1000
- PGID=1000
- URL=mysite.com
- SUBDOMAINS=www,staging
- VALIDATION=dns
- DNSPLUGIN=cloudflare #optional
- EMAIL=me@mail.com #optional
- ONLY_SUBDOMAINS=false #optional
- STAGING=false #optional
volumes:
- /docker-confs/swag/config:/config
ports:
- 443:443
- 80:80 #optional
restart: unless-stopped
root-image:
image: ghcr.io/me/root-image
container_name: root-image
restart: unless-stopped
subdomain-image:
image: ghcr.io/me/subdomain-image
container_name: subdomain-image
restart: unless-stopped
- 为我的根映像定义了一个代理 conf(在 swag/config/nginx/proxy-confs/root-image.subfolder.conf)
location / {
include /config/nginx/proxy.conf;
resolver 127.0.0.11 valid=30s;
set $upstream_app root-image;
set $upstream_port 3000;
set $upstream_proto http;
proxy_pass $upstream_proto://$upstream_app:$upstream_port;
}
- 注释掉 nginx 的默认
location / {}
块(在 swag/config/nginx/site-confs/default) - 为我的子域图像定义了一个代理 conf(在 swag/config/nginx/proxy-confs/subdomain-image.subdomain.conf)
server {
listen 443 ssl;
listen [::]:443 ssl;
server_name staging.*;
include /config/nginx/ssl.conf;
client_max_body_size 0;
location / {
include /config/nginx/proxy.conf;
resolver 127.0.0.11 valid=30s;
set $upstream_app subdomain-image;
set $upstream_port 443;
set $upstream_proto https;
proxy_pass $upstream_proto://$upstream_app:$upstream_port;
}
}
两个图像都暴露了端口 3000。现在我的根图像工作正常(好的!),但我的子域图像出现 502 错误。我检查了 nginx 错误日志,但它没有显示任何对我有意义的东西:
*35 connect() failed (111: Connection refused) while connecting to upstream, client: xxx.xxx.xxxx.xxx, server: staging.*, request: "GET /favicon.ico HTTP/2.0", upstream: "https://xxx.xxx.xxx:443/favicon.ico", host: "staging.mysite.com", referrer: "https://staging.mysite.com"
所有 3 个容器的 Docker 日志也很好(没有显示任何警告或错误)。
哪一步我出错了,或者我错过了什么?感谢您的帮助
解决方案
推荐阅读
- php - 注意:未定义索引:is_popup
- rider - Rider IDE - Razor 页面 HTML 突出显示?
- java - 错误:com.android.builder.dexing.DexArchiveBuilderException: 无法处理 ...\.gradle\caches\modules-2\files-2.1\javaee\javaee-api\5\
- hibernate - 无法设置从 Servlet 检索的 JSP 页面中的值
- python - 合并两个不同的日期时间列以形成一个序列
- c++ - 如何应用使默认构造函数有条件地显式?
- css - 元素 UI el-collapse 在前面如果其他组件
- javascript - Android Pie (9.0) 中的 Ionic 4 应用程序登录问题
- scala - 如何在没有 ExecutionContext.global 和 IOApp 的情况下在猫效果中使用计时器?
- scala - 我可以使用类的类型注释来决定类方法的结果类型吗?