Skip to content

shell utility incorporating envsubst to derive generic nginx proxy settings from environment variables

Notifications You must be signed in to change notification settings

iilei/nginx-dynamic-proxies

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Generate nginx config based on env vars

Utility to map env vars by convention to proxy settings.

Requirements

Usage

Assuming your environment variables define zero or more of

export <CUSTOM_PREFIX:API>_PROXY_ENDPOINT_<PROXY_NAME>=https://example.com
export <CUSTOM_PREFIX:API>_PROXY_PATH_<PROXY_NAME>=/example/

Executing ./generate-proxy-config.sh creates a proxy setting for you to be used with nginx.

As an example:

export API_PROXY_ENDPOINT_FOO_BAR=https://blah.example.com/foobar
export API_PROXY_PATH_FOO_BAR=/foo/bar/
export API_PROXY_ENDPOINT_FOO_BAZ=https://blah.example.com/foobaz
export API_PROXY_PATH_FOO_BAZ=/foo/baz/

./generate-proxy-config.sh

writes to ./proxy.conf:

location /foo/bar/ {
    proxy_pass https://blah.example.com/foobar;
}

location /foo/baz/ {
    proxy_pass https://blah.example.com/foobaz;
}

Or, equivalent to the above with custom namespace and custom output path:

export MY_SERVICE_API_PROXY_ENDPOINT_FOO_BAR=https://my-service.example.com/foobar
export MY_SERVICE_API_PROXY_PATH_FOO_BAR=/my-service/foobar/

./generate-proxy-config.sh MY_SERVICE_API  /etc/nginx/proxy.conf

writes to /etc/nginx/proxy.conf:

location /my-service/foobar/ {
    proxy_pass https://my-service.example.com/foobar;
}


You can now either reference it or directly embed it in your default.conf:

# Your default.conf.tpl
server {
    # basic config

    # **********************************************************
    # start env-based proxy config
    # end env-based proxy config
    # **********************************************************
}

Replace the # start env-based proxy config-Line:

sed "/# start env-based proxy config/r proxy.conf" default.conf.tpl >| default.conf

Test framework

See rylnd/shpec

Contribute

Bug Reports and Pull Requests welcome at github.com/iilei/nginx-dynamic-proxies

About

shell utility incorporating envsubst to derive generic nginx proxy settings from environment variables

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published