All Projects → shufo → Nginx Consul Template

shufo / Nginx Consul Template

Licence: mit
A dynamic configurable Nginx with Consul.

Programming Languages

shell
77523 projects

Projects that are alternatives of or similar to Nginx Consul Template

Netcore Postgres Oauth Boiler
A basic .NET Core website boilerplate using PostgreSQL for storage, Adminer for db management, Let's Encrypt for SSL certificates and NGINX for routing.
Stars: ✭ 57 (-17.39%)
Mutual labels:  nginx
Flask Restful Authentication
An example for RESTful authentication using nginx, uWSGI, Flask, MongoDB and JSON Web Token(JWT).
Stars: ✭ 63 (-8.7%)
Mutual labels:  nginx
Fail2ban.webexploits
This custom Fail2Ban filter and jail will deal with all scans for common Wordpress, Joomla and other Web Exploits being scanned for by automated bots and those seeking to find exploitable web sites.
Stars: ✭ 67 (-2.9%)
Mutual labels:  nginx
Chef Openresty
An Opscode Chef cookbook for the OpenResty NGINX bundle
Stars: ✭ 58 (-15.94%)
Mutual labels:  nginx
Docker Magento Mutagen
Mage2click Docker-based development environment for Magento with mutagen.io sync for files on macOS
Stars: ✭ 64 (-7.25%)
Mutual labels:  nginx
Lua Io Nginx Module
"Non-Blocking" Lua Disk I/O APIs for OpenResty - Powered by Nginx's Thread Pool
Stars: ✭ 64 (-7.25%)
Mutual labels:  nginx
Vpstoolbox
一键安装Trojan-GFW代理,Hexo博客,Nextcloud等應用程式。
Stars: ✭ 1,080 (+1465.22%)
Mutual labels:  nginx
Reading
我的阅读资料
Stars: ✭ 69 (+0%)
Mutual labels:  nginx
Zstd Nginx Module
Nginx modules for the Zstandard compression
Stars: ✭ 64 (-7.25%)
Mutual labels:  nginx
Nginx Sysvinit Script
Linux Standard Base compliant SysVinit script for nginx.
Stars: ✭ 66 (-4.35%)
Mutual labels:  nginx
Ip2geo
Импортер ipgeo-данных в файлы, понятные для nginx geoip module, с поддержкой кодов регионов РФ.
Stars: ✭ 59 (-14.49%)
Mutual labels:  nginx
Alpine Nginx
Minimalist Nginx image based on Alpine linux (6 MB)
Stars: ✭ 63 (-8.7%)
Mutual labels:  nginx
Setup Nginx Webserver
🚀Setup a perfect webserver on CentOS/Redhat 7.x guide with understanding.
Stars: ✭ 65 (-5.8%)
Mutual labels:  nginx
Ngx dynamic limit req module
The ngx_dynamic_limit_req_module module is used to dynamically lock IP and release it periodically.
Stars: ✭ 57 (-17.39%)
Mutual labels:  nginx
Ngxfmt
nginx conf formatter
Stars: ✭ 69 (+0%)
Mutual labels:  nginx
Lobsters Ansible
Ansible playbook for lobste.rs
Stars: ✭ 56 (-18.84%)
Mutual labels:  nginx
Microgateway
IBM API Connect Microgateway framework, built on Node.js & Nginx
Stars: ✭ 1,131 (+1539.13%)
Mutual labels:  nginx
Dockerfiles
lots of dockerfiles, based on alpine
Stars: ✭ 69 (+0%)
Mutual labels:  nginx
Record
✨✨都是自己输出和看过觉得不错的文章,欢迎star、watch!!同时欢迎推荐新文章、书籍和视频!!
Stars: ✭ 69 (+0%)
Mutual labels:  nginx
Leevis.com
Blog
Stars: ✭ 65 (-5.8%)
Mutual labels:  nginx

nginx-consul-template

DockerHub Repository: https://registry.hub.docker.com/u/shufo/nginx-consul-template/

Overview

This repository contains a scripts for creating configurable load balancer Consul Key-Value store API with nginx and consul-template.

Requirements

Usage

  • Run
docker run -d -p 80:80 \
    --link consul:consul \
    -e "CONSUL_KV_PREFIX=nginx" \
    shufo/nginx-consul-template
  • Custom nginx config

Inside the container there is a file config.json which contains default values for all of the configuration options that are read by the consul template. When this container starts these default values are pre-loaded into consul, so that when it comes to reading these values when the template is parsed, there are already default values.

However you can change these default values by providing your own config.json:

docker run -d -p 80:80 \
    -v /path/to/config.json:/config.json \
    --link consul:consul \
    -e "CONSUL_KV_PREFIX=nginx" \
    shufo/nginx-consul-template
  • Custom template
docker run -d -p 80:80 \
    -v $(pwd)/config.json:/config.json \
    -v /path/to/nginx.conf.ctmpl:/etc/nginx/nginx.conf.ctmpl \
    -e "CONSUL_KV_PREFIX=nginx" \
    shufo/nginx-consul-template
  • Dynamic configuration change via Consul API.
curl -X PUT -d "/var/log/nginx/error.log" http://consul_host:8500/v1/kv/nginx/error_log
  • Changing the consul hostname

By default this container tries to connect to a consul server running on localhost. If you want to specify a different location for the consul server, set the CONSUL_PORT_8500_TCP_ADDR environmental variable. If you are linking this container to the consul container then you should set the CONSUL_PORT_8500_TCP_ADDR variable to the alias of the consul container:

docker run -d -p 80:80 \
    -v /path/to/config.json:/config.json \
    --link consul:consul \
    -e "CONSUL_KV_PREFIX=nginx" \
    -e "CONSUL_PORT_8500_TCP_ADDR=consul" \
    shufo/nginx-consul-template

Example

This repository contains a example dockerize application build with vagrant machine.(Requires Vagrant and Ansible)

  • Setup VM and docker containers.
make install
  • Change configuration.
curl -X PUT -d "/var/log/nginx/error.log" http://172.17.9.101:8500/v1/kv/nginx/error_log
  • Ensure nginx conf is properly rewrited.
docker exec -it nodes_nginx_1 cat /etc/nginx/nginx.conf
  • Set tag to application upstream.
curl -X PUT -d "0.0.1" http://172.17.9.101:8500/v1/kv/nginx/http/server/httpd/upstream/current

This will set upstream of service named httpd to tagged with 0.0.1 containers. Service registration is automated by registrator.

  • If something goes wrong, restart all containers
make restart

How to

  • Consul data persistence
docker run -d -v /mnt:/data progrium/consul:latest -server -bootstrap -data-dir /data -ui-dir /ui
  • Set multiple value in same key
# Edit config.json
# Set JSON key-value pair as a Value.
"location": {
"proxy_set_header": "{\"X-Real-IP\": \"$remote_addr\", \"X-Forwarded-For\": \"$proxy_add_x_forwarded_for\", \"X-Forwarded-Proto\": \"$scheme\", \"Host\": \"$host\"}"
}

# Edit consul template file
{{ range $key, $pairs := tree "location" | byKey }}
  {{ range $pair := $pairs }}
    {{ range $key, $value := printf "location/%s"  $pair.Key | key | parseJSON }}
    	{{ $key }}{{ $value }}
    {{ end }}
  {{ end }}
{{ end }}
  • Run with Host networking
docker 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

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].