如何解决Docker Compose:将针对特定域和子域的容器请求重新路由到容器
我有一个由网络服务器容器组成的docker-compose,该容器托管一个在某些时候发送webhooks的Web应用程序。我试图将这些webhooks重新路由到80端口的postbin容器,这可以帮助我调试从第一个容器发出的webhooks。
我以前的研究导致通过Nginx容器使用反向代理,但是我没有找到有关如何实现将请求重新路由到包含路径或子域的容器的文档。
您有什么线索可以和我分享吗?
解决方法
我正在使用像这样的模板来实现这一目标。对https://subdomain.exampledomain.com的请求将由nginx转发到https:// local_ip:12345
# nginx.subdomain.exampledomain.conf
server {
listen 443 ssl;
server_name subdomain.exampledomain.com;
# nginx should have read access to all clients certs
ssl_certificate /etc/letsencrypt/live/subdomain.exampledomain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/subdomain.exampledomain.com/privkey.pem;
#ssl on;
#listen 443 ssl;
ssl_session_cache builtin:1000 shared:SSL:10m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4;
ssl_prefer_server_ciphers on;
location / {
# local_ip is the host ip
proxy_pass https://{{ local_ip }}:12345 ;
proxy_redirect https://{{ local_ip }}:12345 https://subdomain.exampledomain.com;
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-Proto $scheme;
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。