{"id":19356530,"url":"https://github.com/factorial-io/haproxy-config","last_synced_at":"2025-10-06T08:07:23.642Z","repository":{"id":46675082,"uuid":"72370918","full_name":"factorial-io/haproxy-config","owner":"factorial-io","description":"Serve multiple docker containers with the help of haproxy and a small python script","archived":false,"fork":false,"pushed_at":"2024-05-21T08:37:03.000Z","size":74,"stargazers_count":6,"open_issues_count":4,"forks_count":1,"subscribers_count":14,"default_branch":"main","last_synced_at":"2025-06-13T22:00:00.516Z","etag":null,"topics":["docker","haproxy","haproxy-configuration","restarts-haproxy"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/factorial-io.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2016-10-30T19:36:03.000Z","updated_at":"2022-04-09T11:13:24.000Z","dependencies_parsed_at":"2024-05-21T10:13:46.850Z","dependency_job_id":"cbbde900-957f-4f3b-859a-0ae0ca639de8","html_url":"https://github.com/factorial-io/haproxy-config","commit_stats":null,"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"purl":"pkg:github/factorial-io/haproxy-config","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/factorial-io%2Fhaproxy-config","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/factorial-io%2Fhaproxy-config/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/factorial-io%2Fhaproxy-config/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/factorial-io%2Fhaproxy-config/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/factorial-io","download_url":"https://codeload.github.com/factorial-io/haproxy-config/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/factorial-io%2Fhaproxy-config/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259888191,"owners_count":22927074,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["docker","haproxy","haproxy-configuration","restarts-haproxy"],"created_at":"2024-11-10T07:04:45.452Z","updated_at":"2025-10-06T08:07:18.432Z","avatar_url":"https://github.com/factorial-io.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# dockerized haproxy\n\nthis docker container provides haproxy and a small python script which will recreate its configuration from available docker container when a container gets started or gets stopped.\n\n## How does it work\n\nhaproxy is listening on port 80 and will forward all requests to a specific docker-image. It uses the hostname to distinguish the containers.\n\nHow does haproxy know about the running docker-containers? There's a python script loosely based on work of Bastian Hoyer which rewrites the haproxy-configuration when a docker-container gets started or gets stopped. It will scan all running docker-containers and get the hostname and port from all running containers via environment-variables. The container set the environment-variable VHOST and (optionally) VPORT to their needs, the configuration utility parses this information and the internal IP of the docker-container and constructs a suitable haproxy-configuration file and restarts haproxy. It listens for docker events and will update the haproxy config on demand.\n\nIf the environment variable `PROVIDE_DEFAULT_BACKEND` is set, then the python script will provide a basic status page listing all environments instead of showing a 503 error.\n\n\n## Environment variables used by haproxy_config:\n\n* `VHOST`  or `VIRTUAL_HOST` the hostnames to use for this docker-container (separate multiple hostnames with a space)\n* `VPORT` or `VIRTUAL_PORT` the port to forward the http-traffic to, defaults to 80\n* `VPATH` the path to filter by requests; this allows you to serve multiple containers under the same domain, but with different url-prefixes. The prefixes get removed when passed to the containers, or when `VPATH_REPLACEMENT` is set, it gets replaced with the value from `VPATH_REPLACEMENT`.\n* `VPATH_REPLACEMENT` sets the replacement path for when `VPATH` is set. This allows you to rewrite the paths completely.\n* `HTTPS_ONLY` will forward traffic for port 80 to port 443 for that given VHOST.\n* `REDIRECT_FROM` redirect from a given hostname. (Separate multiple hostnames with a space)\n* `SSH` if a container exposes this environment variable, all ssh-traffic to 22 is forwarded to the container. This setting can be used only for one container.\n* `HTTP_AUTH_USER` and `HTTP_AUTH_PASS` protect an instance via HTTP-Auth.\n\n**Example**\n\nrunning this docker-command will instruct haproxy to forward all https traffic for `my.domain.tld` to port `8888` inside the container\n\n```\ndocker run \\\n  -e VHOST=my.domain.tld \\\n  -e VPORT=8888 \\\n  -e VPATH=/foo \\\n  -e VPATH_REPLACEMENT=/bar \\\n  -e HTTPS_ONLY=1 \\\n  -e REDIRECT_FROM=old.domain.tld superold.domain.tld\\\n  mydocker\n```\n\nThis will instruct haproxy forward all http and https traffic for `my.domain.tld/fooxxx` to port `8888` inside `mydocker`-container and path `/barxxx` . It will also redirect all traffic for `old.domain.tld` to `my.domain.tld`\n\n## Pull the container via\n\n```\ndocker pull factorial/haproxy-config:\u003cVERSION\u003e\n```\n\n## Build the container locally\n\n```\ndocker build --tag=factorial/haproxy-config .\n```\n\n## Run the container\n\n```\ndocker run \\\n  -v /var/run/docker.sock:/var/run/docker.sock \\\n  -v /dev/log:/dev/log \\\n  -e SSL_MODE=CUSTOM|LETS_ENCRYPT|NONE \\\n  -e LETS_ENCRYPT_MAIL=\u003cyour-admin-email-address\u003e \\\n  -e PROVIDE_DEFAULT_BACKEND=1 \\\n  -p 80:80 \\\n  -p 443:443 \\\n  -p 1936:1936 \\\n  --privileged \\\n  --name haproxy \\\n  -d \\\n  factorial/haproxy-config\n```\n\nThe environment variables `SSL_MODE`, `LETS_ENCRYPT_MAIL` and `PROVIDE_DEFAULT_BACKEND` are optional:\n\n * if `SSL_MODE` is set to `LETS_ENCRYPT` then for every domain a letsencrypt certificate will be created. If you want to use your own certificates, set `SSL_MODE` to `CUSTOM` and map your certificates via a volume-mount to `/etc/haproxy/ssl`. Disable SSL by setting `SSL_MODE` to `NONE`. The default value is `LETS_ENCRYPT`\n * `LETS_ENCRYPT_MAIL` is needed when you want to use SSL certificates from LetsEncrypt.\n * If you set `PROVIDE_DEFAULT_BACKEND` you'll get a nice and shiny overview page when haproxy can't serve your request. This is most useful if you use haproxy-config for local development. **PLEASE DO NOT USE IN PRODUCTION**\n\nNote: if you want that haproxy handles SSL-traffic, you'll need to map the corresponding directory into the haproxy-container and listen also on port 443.\n\n## Docker networks\n\nWith version 1.1.0 docker networks are supported, Please make sure, that the haproxy container can connect to the networks of your docker-container:\n\n```\ndocker network connect haproxy \u003cyour-network-name\u003e\n```\n(Obsolote since 1.3.0, but might be necessary in certain environments)\n\n## Changelog\n\n### 2.0.0\n\n- Rework SSL-handling and fix various bugs with it. haproxy-config can either handle SSL-connections with custom scertificates, or will use letsencrypt for certificate-handling. See the docs for the evironment variable `SSL_MODE`\n- Haproxy will leave private networks if it is the only container participating in that network\n- letsencrypt certificates get renwed automatically now\n- ssl, specifically letsencrypt is enabled by default\n- various bug fixes\n\n### 1.3.2\n\n- Display `VPATH` also on the landing page.\n\n### 1.3.1\n\n- When using `VPATH` allow a different path to be used in the container using `VPATH_REPLACEMENT`\n\n### 1.3.0\n- Use haproxy 2.2 wich supports HTTP/2 (now working correctly)\n- haproxy will autojoin private networks if there's a container which wants to be exposed using the environment variables\n- Add support for http-auth via `HTTP_AUTH_USER` and `HTTP_AUTH_PASS`\n- supports SSL certificates from LetsEncrypt if environment variable `LETS_ENCRYPT` is set.\n- Provide a default backend listing all containers with their urls as a table (optional)\n\n### 1.2.2\n- Use haproxy 1.9 which supports HTTP/2\n- support url-prefixe via `VPATH`\n- use `hdr(host)` instead of `hdr_dom(host)` to support domains and subdomains (e.g. example.com and docs.example.com)\n\n### 1.2.1\n- add `EXPOSED_NETWORK` to expose an IP of a specific network to the haproxy config\n\n### 1.2.0\n\n- rewrite core-logic, use docker events to update haproxy-configs when sth changes\n- use ninja2 for creating a new configuration file from a template-file\n- support for regex via VHOST_REGEX\n- support for multiple VHOSTs, separate them with a space\n- support for multiple redirects, separate them with a space\n\n### 1.1.0\n\n  - support for docker networks\n  - support for `VIRTUAL_HOST` and `VIRTUAL_PORT`\n  - support for forwarding SSH-traffic to a specific container\n\n### 1.0.2\n  - bind also to port 8080\n\n### 1.0.1\n  - enhance documentation\n  - fix race condition of spawning multiple haproxy instances\n\n### 1.0.0\n  - initial release\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffactorial-io%2Fhaproxy-config","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffactorial-io%2Fhaproxy-config","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffactorial-io%2Fhaproxy-config/lists"}