GithubHelp home page GithubHelp logo

christianwitts / nginx-service-generator Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 1.0 5.22 MB

A simple upstream service generator from zookeeper configuration metadata

License: BSD 2-Clause "Simplified" License

Go 78.12% Shell 21.88%
nginx zookeeper go

nginx-service-generator's Introduction

nginx-service-generator

A simple upstream service generator from zookeeper configuration metadata

Purpose

To dynamically generate nginx upstream proxy configuration based on your zookeeper service discovery meta-data

Features

  • Checks in with Zookeeper every 10 seconds
  • Hashes the configuration so as not to rewrite unless needed
  • Can use a configuration file, as well as optionally overriding parameters via the command line
  • Hot configuration file reloading via kill -s SIGHUP <PID> or supplying the -configUpdateInterval flag with a duration, ie. -configUpdateInterval=30s
  • Removes services that have no end-points configured

Releases

Example

Given a zookeeper node information layout as

/services/<my-service-name>/instances
[my-services-server_port]

and a template file like the default

upstream {{.Service}} {
    {{range .UpstreamEndpoints}}server {{.}};{{end}}
}

server {
    listen {{.ListenPort}};
    server_name {{.HostFQDN}};

    location / {
        proxy_set_header HOST               $host;
        proxy_set_header X-Forwarded-Proto  $scheme;
        proxy_set_header X-Real-IP          $remote_addr;
        proxy_set_header X-Forwarded-For    $proxy_add_x_forwarded_for;

        proxy_pass http://{{.Service}};
    }
}

a config file that looks like

[default]
nginx-root = /etc/nginx
zookeeper-nodes = 127.0.0.1:2181
service-root = /services
service-check-interval = 10
nginx-reload-command = sv reload nginx
fqdn-subdomain = api
fqdn-postfix = example.com
listen-port = 80

running the following command

./service-generator -config example.config

will yield a service like

upstream my-service-name {
    server my-services-server:port;
}

server {
    listen 80;
    server_name my-service-name.api.example.com;

    location / {
        proxy_set_header HOST               $host;
        proxy_set_header X-Forwarded-Proto  $scheme;
        proxy_set_header X-Real-IP          $remote_addr;
        proxy_set_header X-Forwarded-For    $proxy_add_x_forwarded_for;

        proxy_pass http://my-service-name;
    }
}

If you wanted to override one or more of your configuration file flags, you can optionally specify a command line parameter, such as

./service-generator -config example.config -fqdn-postfix example2.com

# Will yield a service file looking like

upstream my-service-name {
    server my-services-server:port;
}

server {
    listen 80;
    server_name my-service-name.api.example2.com;

    location / {
        proxy_set_header HOST               $host;
        proxy_set_header X-Forwarded-Proto  $scheme;
        proxy_set_header X-Real-IP          $remote_addr;
        proxy_set_header X-Forwarded-For    $proxy_add_x_forwarded_for;

        proxy_pass http://my-service-name;
    }
}

The resultant configuration file will be soft-linked from sites-available to sites-enabled, and nginx will get reloaded so that the configuration is up to date.

This will continue running in the background, at the interval specified by service-check-interval in the configuration file, or as a command line parameter.

You can create your configuration file using the -dumpflags command line parameter.

./service-generator -dumpflags > default.config

License

2-clause BSD

nginx-service-generator's People

Contributors

christianwitts avatar

Watchers

 avatar  avatar

Forkers

agottepu

nginx-service-generator's Issues

Dependabot cannot be upgraded to GitHub-native version due to unsupported `dep` package manager

Dependabot Preview will be shut down on August 3rd, 2021.

It appears that this repository has configured updates for dep.

The GitHub-native version of Dependabot does not support dep, which was deprecated as of 2020.
Guidance from the dep maintainers is to upgrade to go mod, which Dependabot supports.

In order to keep getting updates for your Go dependencies, you'll need to migrate to go mod and add a Dependabot configuration for it to this repository.

Dependabot couldn't find a Gopkg.toml for this project

Dependabot couldn't find a Gopkg.toml for this project.

Dependabot requires a Gopkg.toml to evaluate your project's current Go dependencies. It had expected to find one at the path: /Gopkg.toml.

If this isn't a Go project, or if it is a library, you may wish to disable updates for it from within Dependabot.

You can mention @dependabot in the comments below to contact the Dependabot team.

Dependabot couldn't find a {go.mod,Gopkg.toml} for this project

Dependabot couldn't find a {go.mod,Gopkg.toml} for this project.

Dependabot requires a {go.mod,Gopkg.toml} to evaluate your project's current Go dependencies. It had expected to find one at the path: /{go.mod,Gopkg.toml}.

If this isn't a Go project, or if it is a library, you may wish to disable updates for it from within Dependabot.

You can mention @dependabot in the comments below to contact the Dependabot team.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.