使用Docker进行HA代理简单转发 [英] HA Proxy simple forwarding with Docker

查看:115
本文介绍了使用Docker进行HA代理简单转发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试学习如何使用HA Proxy转发HTTP通信。首先,我想我会使用Docker并陷入困境。

I am attempting to learn how to forward http traffic with HA Proxy. To get started I thought I would use Docker and have come stuck.

尝试执行的转发流量如下

The forwarding traffic im attempting to do looks like this

ha-proxy container port 81
>>> forward to
nginx container port 8088

当我从浏览器加载ha代理容器时网址 http:// localhost:81 / 我收到的错误消息是

When I load the ha proxy container from my browser with the url http://localhost:81/ The error message I get is

503服务不可用没有服务器可用于处理此请求。


我的设置如下所示。

My setup looks like the following.

nginx-容器

当我加载 http:// localhost:8088 / 我得到了正确的欢迎使用nginx!主页。

When I load http://localhost:8088/ I get the correct Welcome to nginx! home page.

即时通讯使用的Docker命令是。我正在使用-net = host ,因此它将其绑定到主机网络。

Docker command im using for that is. Im using --net=host so it binds it the host network.

docker run --name myapp-backend -p 8088:80 -d --net=host  nginx:1.15.0-alpine  

Ha代理

Dockerfile

FROM haproxy:alpine
COPY haproxy.cfg /usr/local/etc/haproxy/haproxy.cfg

haproxy.cfg

global
    log 127.0.0.1 local0
    maxconn 4096

defaults
    log global
    mode http
    option httplog
    option dontlognull
    retries 3
    redispatch
    maxconn 2000
    contimeout 5000
    clitimeout 50000
    srvtimeout 50000

frontend http-in
    bind *:81
    acl myapp-frontend hdr(host) -i localhost
    use_backend myapp-backend if myapp-frontend

backend myapp-backend
    balance roundrobin
    option http-server-close
    server myapp-server-1 localhost:8088 check

启动HA代理

   docker build -t rob-haproxy .
   docker run --name ha-proxy -p 81:81  --net=host -d rob-haproxy

我的想法是ha代理配置文件haproxy.cfg出现问题。

My thinking is that I have something wrong with the ha proxy config file haproxy.cfg. Any advice much appreciated.

推荐答案

我按照Miq的建议将其添加到自己的docker网络中。但这本身还不够,所以我还简化了ha配置。

I went down the route of adding it to its own docker network as per Miq suggestion. However this was not enough on its own so I also simplified the ha config.

下面是现在的样子

global
  quiet

defaults
  mode http
  maxconn 5000

  timeout connect 5s
  timeout client  20s
  timeout server  20s

frontend public
    bind *:81
    default_backend apps

backend apps
    server myapp-backend myapp-backend:80 check

bash

docker network create elk || true
docker run --name myapp-backend -p 8088:80 -d --net=elk  nginx:1.15.0-alpine
docker run --name rob-haproxy -p 81:81 --net=dev-d rob-haproxy-image

这篇关于使用Docker进行HA代理简单转发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆