{"id":16611777,"url":"https://github.com/shufo/nginx-consul-template","last_synced_at":"2025-10-28T12:39:55.474Z","repository":{"id":2852246,"uuid":"39361249","full_name":"shufo/nginx-consul-template","owner":"shufo","description":"A dynamic configurable Nginx with Consul.","archived":false,"fork":false,"pushed_at":"2023-12-15T11:37:49.000Z","size":22,"stargazers_count":76,"open_issues_count":2,"forks_count":19,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-03-15T11:11:29.802Z","etag":null,"topics":["consul-template","docker","nginx"],"latest_commit_sha":null,"homepage":"https://registry.hub.docker.com/u/shufo/nginx-consul-template/","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shufo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-07-20T03:26:04.000Z","updated_at":"2023-05-12T16:42:23.000Z","dependencies_parsed_at":"2022-09-01T03:40:22.760Z","dependency_job_id":null,"html_url":"https://github.com/shufo/nginx-consul-template","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shufo%2Fnginx-consul-template","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shufo%2Fnginx-consul-template/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shufo%2Fnginx-consul-template/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shufo%2Fnginx-consul-template/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shufo","download_url":"https://codeload.github.com/shufo/nginx-consul-template/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243830949,"owners_count":20354854,"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":["consul-template","docker","nginx"],"created_at":"2024-10-12T01:39:25.413Z","updated_at":"2025-10-28T12:39:50.428Z","avatar_url":"https://github.com/shufo.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"nginx-consul-template\n==============================\n\nDockerHub Repository: https://registry.hub.docker.com/u/shufo/nginx-consul-template/\n\n## Overview\n\nThis repository contains a scripts for creating configurable load balancer [Consul](https://www.consul.io/) Key-Value store API with [nginx](http://nginx.org/en/) and [consul-template](https://github.com/hashicorp/consul-template).\n\n## Requirements\n\n- [Docker](https://www.docker.com/) (Tested on 1.6.2)\n- [Consul](https://www.consul.io/) (Tested on 0.5.2)\n\n## Usage\n\n- Run \n\n```\ndocker run -d -p 80:80 \\\n    --link consul:consul \\\n    -e \"CONSUL_KV_PREFIX=nginx\" \\\n    shufo/nginx-consul-template\n```\n\n- Custom nginx config\n\nInside the container there is a file `config.json` which contains default values for all of the configuration\noptions that are read by the consul template. When this container starts these default values are pre-loaded\ninto consul, so that when it comes to reading these values when the template is parsed, there are already default\nvalues.\n\nHowever you can change these default values by providing your own `config.json`:\n\n```\ndocker run -d -p 80:80 \\\n    -v /path/to/config.json:/config.json \\\n    --link consul:consul \\\n    -e \"CONSUL_KV_PREFIX=nginx\" \\\n    shufo/nginx-consul-template\n```\n\n- Custom template\n\n```\ndocker run -d -p 80:80 \\\n    -v $(pwd)/config.json:/config.json \\\n    -v /path/to/nginx.conf.ctmpl:/etc/nginx/nginx.conf.ctmpl \\\n    -e \"CONSUL_KV_PREFIX=nginx\" \\\n    shufo/nginx-consul-template\n```\n\n- Dynamic configuration change via Consul API.\n\n```\ncurl -X PUT -d \"/var/log/nginx/error.log\" http://consul_host:8500/v1/kv/nginx/error_log\n```\n\n- Changing the consul hostname\n\nBy default this container tries to connect to a consul server running on localhost. If you want to specify a different\nlocation for the consul server, set the `CONSUL_PORT_8500_TCP_ADDR` environmental variable. If you are linking this\ncontainer to the consul container then you should set the `CONSUL_PORT_8500_TCP_ADDR` variable to the alias of the\nconsul container:\n```\ndocker run -d -p 80:80 \\\n    -v /path/to/config.json:/config.json \\\n    --link consul:consul \\\n    -e \"CONSUL_KV_PREFIX=nginx\" \\\n    -e \"CONSUL_PORT_8500_TCP_ADDR=consul\" \\\n    shufo/nginx-consul-template\n```\n\n\n## Example\n\nThis repository contains a example dockerize application build with vagrant machine.(Requires [Vagrant](https://www.vagrantup.com/) and [Ansible](http://docs.ansible.com/intro_installation.html))\n\n- Setup VM and docker containers.\n\n```\nmake install\n```\n\n- Change configuration.\n\n```\ncurl -X PUT -d \"/var/log/nginx/error.log\" http://172.17.9.101:8500/v1/kv/nginx/error_log\n```\n\n- Ensure nginx conf is properly rewrited.\n\n```\ndocker exec -it nodes_nginx_1 cat /etc/nginx/nginx.conf\n```\n\n- Set tag to application upstream.\n\n```\ncurl -X PUT -d \"0.0.1\" http://172.17.9.101:8500/v1/kv/nginx/http/server/httpd/upstream/current\n```\n\nThis will set upstream of service named `httpd` to tagged with `0.0.1` containers. Service registration is automated by [registrator](https://registry.hub.docker.com/u/sttts/registrator/).\n\n- If something goes wrong, restart all containers\n\n```\nmake restart\n```\n\n## How to\n\n- Consul data persistence\n\n```\ndocker run -d -v /mnt:/data progrium/consul:latest -server -bootstrap -data-dir /data -ui-dir /ui\n```\n\n- Set multiple value in same key\n\n```\n# Edit config.json\n# Set JSON key-value pair as a Value.\n\"location\": {\n\"proxy_set_header\": \"{\\\"X-Real-IP\\\": \\\"$remote_addr\\\", \\\"X-Forwarded-For\\\": \\\"$proxy_add_x_forwarded_for\\\", \\\"X-Forwarded-Proto\\\": \\\"$scheme\\\", \\\"Host\\\": \\\"$host\\\"}\"\n}\n\n# Edit consul template file\n{{ range $key, $pairs := tree \"location\" | byKey }}\n  {{ range $pair := $pairs }}\n    {{ range $key, $value := printf \"location/%s\"  $pair.Key | key | parseJSON }}\n    \t{{ $key }}{{ $value }}\n    {{ end }}\n  {{ end }}\n{{ end }}\n```\n\n- Run with Host networking\n\n```\ndocker run -d --net host -v $(pwd)/config.json:/config.json -e \"CONSUL_KV_PREFIX=nginx\" -e \"CONSUL_PORT_8500_TCP_ADDR=CONSUL_HOST_IP\" shufo/nginx-consul-template\n```\n\n## Contributing\n\n1. Fork it\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create new Pull Request\n\n## Contributors\n\n\u003c!-- readme: collaborators,contributors -start --\u003e\n\u003ctable\u003e\n\u003ctr\u003e\n    \u003ctd align=\"center\"\u003e\n        \u003ca href=\"https://github.com/shufo\"\u003e\n            \u003cimg src=\"https://avatars.githubusercontent.com/u/1641039?v=4\" width=\"100;\" alt=\"shufo\"/\u003e\n            \u003cbr /\u003e\n            \u003csub\u003e\u003cb\u003eShuhei Hayashibara\u003c/b\u003e\u003c/sub\u003e\n        \u003c/a\u003e\n    \u003c/td\u003e\n    \u003ctd align=\"center\"\u003e\n        \u003ca href=\"https://github.com/emmetog\"\u003e\n            \u003cimg src=\"https://avatars.githubusercontent.com/u/1182891?v=4\" width=\"100;\" alt=\"emmetog\"/\u003e\n            \u003cbr /\u003e\n            \u003csub\u003e\u003cb\u003eEmmet O'Grady\u003c/b\u003e\u003c/sub\u003e\n        \u003c/a\u003e\n    \u003c/td\u003e\n    \u003ctd align=\"center\"\u003e\n        \u003ca href=\"https://github.com/smiller171\"\u003e\n            \u003cimg src=\"https://avatars.githubusercontent.com/u/3587913?v=4\" width=\"100;\" alt=\"smiller171\"/\u003e\n            \u003cbr /\u003e\n            \u003csub\u003e\u003cb\u003eScott Miller\u003c/b\u003e\u003c/sub\u003e\n        \u003c/a\u003e\n    \u003c/td\u003e\n    \u003ctd align=\"center\"\u003e\n        \u003ca href=\"https://github.com/malaiwah\"\u003e\n            \u003cimg src=\"https://avatars.githubusercontent.com/u/10375593?v=4\" width=\"100;\" alt=\"malaiwah\"/\u003e\n            \u003cbr /\u003e\n            \u003csub\u003e\u003cb\u003eMichel Belleau\u003c/b\u003e\u003c/sub\u003e\n        \u003c/a\u003e\n    \u003c/td\u003e\u003c/tr\u003e\n\u003c/table\u003e\n\u003c!-- readme: collaborators,contributors -end --\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshufo%2Fnginx-consul-template","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshufo%2Fnginx-consul-template","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshufo%2Fnginx-consul-template/lists"}