Skip to content
Snippets Groups Projects
Select Git revision
  • 4a06b9dfd608e80339df11aafdcd80e432095c2a
  • master default protected
  • testfix
  • production protected
4 results

consul_proxy

Consul Proxy

A service router and load balancer that uses Consul for configuration and service lookups.

Building

rebar3 compile

Running

docker run --name consul_proxy --net=host -d \
  -e CONSUL_PROXY_HTTP_PORT="80" \
  -e CONSUL_PROXY_CONSUL_URLS="\"http://localhost:8500\"" \
  -p 80:80 \
  -p 8081:8081 \
  -p 8082:8082 \
  -p 8083:8083 \
  erlangninja/consul_proxy

Configuration

Domains

Path is consul_proxy/domains/[DOMAIN]

Services

{
  "ServiceName" : "...",
  "ServiceID" : "...",
  "ServiceTags" : "..."
}

Nodes

{
  "ServiceNodes" : [
      "ServiceHost" : "...",
      "ServiceAddress" : "...",
      "ServicePort" : "..."
  ]
}

Resolver

{
  "ServiceResolver" : "..."
}

Headers

{
  "Headers" : {
    "Upstream" : [],
    "Downstream" : []
  }
}

Scripts

Path is consul_proxy/scripts/[NAME]

Properies passed to the script are a combination of the domain configuration and the following request propeties.

{request, [
    {method, "..."},
    {domain, "..."},
    {port, "..."},
    {path, "..."},
    {query, []},
    {headers, []},
    {cookies, []},
    {meta, [
        {request_id, "..."},
        {initial_host, "..."},
        {host_capture, "..."}
    ]}
]}.

Erlang

When the properties are passed to an Erlang script the properties are bound as a proplist to the variable Props. The script must return a proplist that contains the domain configuration.

Request = proplists:get_value(request, Props, []),
Meta = proplists:get_value(meta, Request, []),
Capture = proplists:get_value(host_capture, Meta, []),
ServiceName = proplists:get_value(<<"service">>, Capture),
[{<<"ServiceName">>, ServiceName}].

Lua

When the properties are passed to a Lua script the properties are bound as a table to the variableprops. The script must return a table that contains the domain configuration.

return {ServiceName = props.request.meta.host_capture.service};

Watchers

Path is consul_proxy/watchers/(kv | nodes | services)

Hijackers

Path is consul_proxy/hijackers

[
  {
    "username" : "...",
    "password" : "...",
    "domains" : [
      "...."
    ]
  }
]

Middlewares

Alias

Auth

Redirect

Rewrite

ACME

Hijack

Load Balancing

Logging