Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
9dbe8a7
Bumping version to 4.0.0
bfren May 4, 2022
7ae1ae4
Removing latest tag from publish
bfren May 4, 2022
ce2fb00
Install jq package
bfren May 4, 2022
40a059f
Load domains config from JSON not bash
bfren May 4, 2022
8a4033e
Init using JSON config
bfren May 4, 2022
a2670a4
Adding JSON schema and sample json
bfren May 4, 2022
011c288
Removing convert from setup
bfren May 4, 2022
a3359e0
Using GitHub file as schema
bfren May 4, 2022
fae4ec4
Removing bash config sample file
bfren May 4, 2022
5bdeff3
Updating loop
bfren May 4, 2022
616d4cb
Updating loop
bfren May 4, 2022
bfee653
Using new conf in nginx-regenerate executable
bfren May 4, 2022
f205e4b
Using new conf in ssl-cleanup
bfren May 4, 2022
1aa2fd2
Updating JSON variable name
bfren May 4, 2022
2d31da3
Using helper functions to get config info
bfren May 4, 2022
c3df568
Re-adding DN while getting info
bfren May 4, 2022
fac4530
Using * to reference all items in array
bfren May 4, 2022
058d2b6
Fixing ssl-cleanup
bfren May 4, 2022
e980ea1
Fixing Domains loops
bfren May 4, 2022
a3e14ed
Updating site config template for new custom property
bfren May 4, 2022
2c2dad6
Updating template comments
bfren May 4, 2022
e82a320
Updating config template comments
bfren May 4, 2022
5779005
Fixing misleading log output
bfren May 4, 2022
09e030c
Merge branch 'main' into v4.0.0
bfren May 4, 2022
6c70e00
Updating README
bfren May 4, 2022
4af4e78
Merge branch 'v4.0.0' of https://github.com/bfren/docker-nginx-proxy …
bfren May 4, 2022
e5d9308
Build jq from source instead of using package
bfren May 4, 2022
3f25437
Build from jq fork instead of original
bfren May 4, 2022
e4e7efa
Using gojq instead of jq
bfren May 4, 2022
78366c0
Reverting to jq
bfren May 4, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,9 @@ jobs:
push: true
platforms: linux/amd64,linux/arm/v7,linux/arm64
tags: |
bfren/nginx-proxy:latest
bfren/nginx-proxy:${{ steps.version_major.outputs.contents }}
bfren/nginx-proxy:${{ steps.version_minor.outputs.contents }}
bfren/nginx-proxy:${{ steps.version.outputs.contents }}
ghcr.io/bfren/nginx-proxy:latest
ghcr.io/bfren/nginx-proxy:${{ steps.version_major.outputs.contents }}
ghcr.io/bfren/nginx-proxy:${{ steps.version_minor.outputs.contents }}
ghcr.io/bfren/nginx-proxy:${{ steps.version.outputs.contents }}
Expand Down
32 changes: 17 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

Nginx Proxy which uses [getssl](https://github.com/srvrco/getssl) to automate requesting and renewing SSL certificates via Let's Encrypt. Certificates are checked for renewal every day - the last check can be viewed in the `/ssl` volume.

As of v4, configuration is handled via a JSON file - see ssl-conf-sample.json for an example and ssl-conf-schema.json for the full file definition.

## Contents

* [Ports](#ports)
Expand All @@ -25,11 +27,11 @@ For SSL certificate requests to work correctly, ports 80 and 443 need mapping fr

## Volumes

| Volume | Purpose |
| -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `/www` | *From base image.* |
| `/sites` | Nginx site configuration, auto-generated on first run based on `conf.sh`. After they are generated, you can alter them to suit their needs. Running `nginx-regenerate` will wipe them all and start again. |
| `/ssl` | Contains auto-generated SSL configuration and certificates (for backup purposes). Your `conf.sh` file should be stored in here for auto-configuration (see `ssl-conf-sample.sh`). Certificate update log (`update.log`) will be created here weekly. |
| Volume | Purpose |
| -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `/www` | *From base image.* |
| `/sites` | Nginx site configuration, auto-generated on first run based on `conf.json`. After they are generated, you can alter them to suit their needs. Running `nginx-regenerate` will wipe them all and start again. |
| `/ssl` | Contains auto-generated SSL configuration and certificates (for backup purposes). Your `conf.json` file should be stored in here for auto-configuration (see `ssl-conf-sample.json`). Certificate update log (`update.log`) will be created here daily. |

## Environment Variables

Expand All @@ -40,20 +42,20 @@ For SSL certificate requests to work correctly, ports 80 and 443 need mapping fr
| `PROXY_LETS_ENCRYPT_EMAIL` | A valid email address | Used by Lets Encrypt for notification emails. | *None* - **required** |
| `PROXY_LETS_ENCRYPT_LIVE` | 0 or 1 | Only set to 1 (to request live certificates) when your config is correct - Lets Encrypt rate limit certificate requests. | 0 |
| `PROXY_SSL_DHPARAM_BITS` | A valid integer | The size of your DHPARAM variables - adjust down only if you have limited processing resources. | 4096 |
| `PROXY_SSL_REDIRECT_TO_CANONICAL` | 0 or 1 | If 1, all requests will be redirected to the primary domain (defined in `conf.sh`). | 0 |
| `PROXY_SSL_REDIRECT_TO_CANONICAL` | 0 or 1 | If 1, all requests will be redirected to the primary domain (defined in `conf.json`). | 0 |
| `PROXY_GETSSL_SKIP_HTTP_TOKEN_CHECK` | true or false | Set to true to enable `getssl`'s [skip HTTP token check](https://github.com/srvrco/getssl/wiki/Config-variables#skip_http_token_checkfalse). | false |

## Helper Functions

| Function | Arguments | Description |
| --------------------- | --------- | ---------------------------------------------------------------------------------------------------------------- |
| `nginx-regenerate` | *None* | Removes Nginx configuration files (in `/sites`) and regenerates based on `conf.sh`. |
| `ssl-cleanup` | *None* | Removes SSL and Nginx configuration files and directories not defined in `conf.sh`. |
| `ssl-init` | *None* | Initialises SSL configuration based on `conf.sh`. |
| `ssl-regenerate` | *None* | Removes SSL configuration files (in `/ssl/certs`) and regenerates based on `conf.sh`. |
| `ssl-regenerate-full` | *None* | Removes SSL configuration files (in `/ssl/certs`), as well as DH parameters, and regenerates based on `conf.sh`. |
| `ssl-request` | *None* | Requests SSL certificates from Lets Encrypt. |
| `ssl-update` | *None* | Attempts to update SSL certificates manually. |
| Function | Arguments | Description |
| --------------------- | --------- | -------------------------------------------------------------------------------------------------------------------------- |
| `nginx-regenerate` | -f: force | Removes non-custom Nginx configuration files (in `/sites`) and regenerates based on `conf.json` (with force, removes all). |
| `ssl-cleanup` | -m: mode | Removes SSL and Nginx configuration files and directories not defined in `conf.json` (mode 0 = dry run, 1 = live). |
| `ssl-init` | *None* | Initialises SSL configuration based on `conf.json`. |
| `ssl-regenerate` | *None* | Removes SSL configuration files (in `/ssl/certs`) and regenerates based on `conf.json`. |
| `ssl-regenerate-full` | *None* | Removes SSL configuration files (in `/ssl/certs`), as well as DH parameters, and regenerates based on `conf.json`. |
| `ssl-request` | *None* | Requests SSL certificates from Lets Encrypt. |
| `ssl-update` | *None* | Attempts to update SSL certificates manually. |

## Nginx Configuration Helpers

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.3.13
4.0.0
2 changes: 1 addition & 1 deletion VERSION_MAJOR
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3
4
2 changes: 1 addition & 1 deletion VERSION_MINOR
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.3
4.0
2 changes: 1 addition & 1 deletion overlay/etc/bf/templates/nginx-proxy.conf.esh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
# Use environment variable PROXY_URI to change this file.
#
# Copyright (c) 2021 bfren
# Copyright (c) 2021-2022 bfren
#======================================================================================================================

#======================================================================================================================
Expand Down
36 changes: 19 additions & 17 deletions overlay/etc/bf/templates/nginx-site.conf.esh
Original file line number Diff line number Diff line change
@@ -1,17 +1,4 @@
<% if [ -z "${DOMAIN_NGXCONF}" ] ; then -%>
#======================================================================================================================
# WARNING: This file is generated. Do not make changes to this file.
# Changes will be overwritten the next time the container is started.
#
# To add server names or aliases please use /ssl/conf.sh (see ssl-conf-sample.sh).
#
# If you need a fully custom configuration then add the following to /ssl/conf.sh:
# NGXCONF["<%= "${DOMAIN_NAME}" %>"]="custom"
# This will stop this file being generated next time the container is started.
#
# Copyright (c) 2021 bfren
#======================================================================================================================
<% else -%>
<% if [ "${DOMAIN_NGXCONF}" = "true" ] ; then -%>
#======================================================================================================================
# You can make changes to this file.
#
Expand All @@ -23,11 +10,26 @@
# d) custom configuration can be added to the /sites/<%= "${DOMAIN_NAME}" %>.d directory -
# these are loaded as part of the HTTPS server block below
#
# If you would like to return to using generated configuration then remove the following from /ssl/conf.sh:
# NGXCONF["<%= "${DOMAIN_NAME}" %>"]=""
# If you would like to return to using generated configuration then remove the following from /ssl/conf.json in the
# object where the primary domain is "<%= "${DOMAIN_NAME}" %>":
# "custom": true
# This will cause this file to be regenerated next time the container is started.
#
# Copyright (c) 2021 bfren
# Copyright (c) 2021-2022 bfren
#======================================================================================================================
<% else -%>
#======================================================================================================================
# WARNING: This file is generated. Do not make changes to this file.
# Changes will be overwritten the next time the container is started.
#
# To add server names or aliases please use /ssl/conf.sh (see ssl-conf-sample.sh).
#
# If you need a fully custom configuration then add the following to /ssl/conf.json in the object where the primary
# domain is "<%= "${DOMAIN_NAME}" %>":
# "custom": true
# This will stop this file being generated next time the container is started.
#
# Copyright (c) 2021-2022 bfren
#======================================================================================================================
<% fi %>
#======================================================================================================================
Expand Down
1 change: 1 addition & 0 deletions overlay/tmp/install
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ bf-echo "Installing packages..."
apk add --no-cache \
bash \
curl \
jq \
openssl
bf-done

Expand Down
5 changes: 3 additions & 2 deletions overlay/usr/bin/bf/nginx-regenerate
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ done

bf-echo "Loading SSL configuration."
source ${BF_INC}/proxy-load-conf.sh
bf-debug "Loaded: ${!DOMAINS[*]}."
bf-debug "Loaded: ${DOMAINS[*]}."


#======================================================================================================================
Expand All @@ -54,7 +54,8 @@ for CFG in "${NGINX_CONFIGS[@]}" ; do
bf-debug " .. ${STRIPPED}"

# the domain has standard config - delete conf file
if [[ -z "${NGXCONF[${STRIPPED}]-}" ]] ; then
CUSTOM_CONF=`get-custom "${STRIPPED}"`
if [[ "${CUSTOM_CONF}" = "false" ]] ; then

bf-debug " .. standard config: remove configuration file"
rm -f ${PROXY_SITES}/${STRIPPED}.conf
Expand Down
10 changes: 5 additions & 5 deletions overlay/usr/bin/bf/ssl-cleanup
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ esac
remove () {

if [ "${MODE}" = "0" ] ; then
bf-echo " .. will remove ${1}/*"
bf-echo " .. will remove ${1}*"
elif [ "${MODE}" = "1" ] ; then
bf-echo " .. removing ${1}/*"
bf-echo " .. removing ${1}*"
bf-rmrf ${1}* > /dev/null 2>&1
fi

Expand All @@ -57,7 +57,7 @@ remove () {

bf-echo "Loading SSL configuration."
source ${BF_INC}/proxy-load-conf.sh
bf-debug "Loaded: ${!DOMAINS[*]}."
bf-debug "Loaded: ${DOMAINS[*]}."


#======================================================================================================================
Expand All @@ -79,7 +79,7 @@ for CFG in "${SSL_CONFIGS[@]}" ; do

# if NAME is not the main PROXY_URI nor in the DOMAINS array, delete everything
[[ "${PROXY_URI}" != "${NAME}" ]] \
&& [[ ! " ${!DOMAINS[*]} " =~ " ${NAME} " ]] \
&& [[ -z "`get-domain ${NAME}`" ]] \
&& remove "${PROXY_SSL_CERTS}/${NAME}"

done
Expand All @@ -105,7 +105,7 @@ for CFG in "${NGINX_CONFIGS[@]}" ; do

# if STRIPPED is not the main PROXY_URI nor in the DOMAINS array, delete everything
[[ "${PROXY_URI}" != "${STRIPPED}" ]] \
&& [[ ! " ${!DOMAINS[*]} " =~ " ${STRIPPED} " ]] \
&& [[ -z "`get-domain ${STRIPPED}`" ]] \
&& remove "${PROXY_SITES}/${STRIPPED}"

done
Expand Down
4 changes: 2 additions & 2 deletions overlay/usr/lib/bf/inc/proxy-check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fi


#======================================================================================================================
# Create arrays and include configuration.
# Load configuration (creates DOMAINS array).
#======================================================================================================================

source ${BF_INC}/proxy-load-conf.sh
Expand All @@ -32,7 +32,7 @@ source ${BF_INC}/proxy-load-conf.sh
# Check whether or not domains have been registered.
#======================================================================================================================

if [ "${#DOMAINS[@]}" = "0" ] ; then
if [ "${#DOMAINS[*]}" = "0" ] ; then
bf-error "No domains have been registered for SSL - please add them to /ssl/conf.sh." "inc/proxy-check.sh"
exit 1
fi
Expand Down
31 changes: 24 additions & 7 deletions overlay/usr/lib/bf/inc/proxy-load-conf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,34 @@


#======================================================================================================================
# Create arrays and include configuration.
# Check JSON configuration file exists.
#======================================================================================================================

SSL_CONF=${PROXY_SSL}/conf.sh
SSL_CONF=${PROXY_SSL}/conf.json
if [ ! -f ${SSL_CONF} ] ; then
bf-error "You must create ${SSL_CONF} - see ssl-conf-sample.sh." "inc/proxy-load-conf.sh"
bf-error "You must create ${SSL_CONF} - see ssl-conf-sample.json." "inc/proxy-load-conf.sh"
exit 1
fi

declare -A DOMAINS
declare -A ALIASES
declare -A NGXCONF

source ${SSL_CONF}
#======================================================================================================================
# Load JSON and create DOMAINS array by selecting primary keys.
#======================================================================================================================

JSON=`cat "${SSL_CONF}" | jq '.'`

declare -a DOMAINS=(`jq -r '.domains[].primary' <<< "${JSON}"`)


#======================================================================================================================
# Gets a domain object from the JSON configuration.
#
# Arguments
# 1 Primary domain name to select
#======================================================================================================================

function get-domain() { jq --arg PRIMARY "${1}" '.domains[] | select(.primary == $PRIMARY)' <<< "${JSON}" ; }

function get-upstream() { get-domain "${1}" | jq -r '.upstream' ; }
function get-aliases() { get-domain "${1}" | jq -r '.aliases[]?' ; }
function get-custom() { get-domain "${1}" | jq -r '.custom == true' ; }
25 changes: 13 additions & 12 deletions overlay/usr/lib/bf/inc/proxy-setup-nginx.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
# Set up Nginx.
#
# Arguments
# 1 Domain name
# 2 Upstream URL
# 3 Name of Domain Aliases array
# 4 Blank (regenerate) or 'custom' (keep) Nginx configuration file
# 1 0 for proxied domain, 1 for domain of the proxy server itself
# 2 Domain name
# 3 Upstream URL
# 4 Name of Domain Aliases array
# 5 Blank (regenerate) or 'custom' (keep) Nginx configuration file
#======================================================================================================================

setup-nginx () {
Expand All @@ -31,20 +32,20 @@ setup-nginx () {
# check for existing configuration file
if [ -f ${CONF} ] ; then

# if empty, remove config so it can be regenerated
if [ -z "${DOMAIN_NGXCONF}" ] ; then
bf-debug " removing and regnerating Nginx configuration" "inc/proxy-setup-nginx.sh"
rm ${CONF}

# otherwise, leave file (allows custom config)
else
# if true, leave file (allows custom config)
if [ "${DOMAIN_NGXCONF}" = "true" ] ; then
bf-debug " keeping existing configuration." "inc/proxy-setup-nginx.sh"
return 0

# otherwise, remove config so it can be regenerated
else
bf-debug " removing and regnerating Nginx configuration" "inc/proxy-setup-nginx.sh"
rm ${CONF}
fi

else

# no need to do anything, be a good log citizen
# no need to remove anything, be a good log citizen
bf-debug " generating default Nginx configuration" "inc/proxy-setup-nginx.sh"

fi
Expand Down
10 changes: 5 additions & 5 deletions overlay/usr/lib/bf/proxy/init
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,16 @@ bf-ok " . done." "proxy/init"
#======================================================================================================================

bf-echo "Setting up domains..." "proxy/init"
for DN in "${!DOMAINS[@]}" ; do
for DN in "${DOMAINS[@]}" ; do

UP=${DOMAINS[${DN}]} # upstream server
AL=${ALIASES[${DN}]} # aliases
CF=${NGXCONF[${DN}]} # use default / custom Nginx config
UP=`get-upstream ${DN}` # upstream server
AL=`get-aliases ${DN}` # aliases
CF=`get-custom ${DN}` # whether or not to use custom Nginx config

bf-echo " .. ${DN}" "proxy/init"

bf-echo " . Nginx..." "proxy/init"
setup-nginx 0 ${DN} "${UP}" "${AL}" "${CF}"
setup-nginx 0 ${DN} ${UP} "${AL}" ${CF}

bf-echo " . SSL..." "proxy/init"
setup-ssl ${DN} "${AL}"
Expand Down
2 changes: 1 addition & 1 deletion overlay/usr/lib/bf/proxy/request
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ bf-done "proxy/request"
#======================================================================================================================

bf-echo "Requesting domain certificates..." "proxy/request"
for DN in "${!DOMAINS[@]}" ; do
for DN in "${DOMAINS[@]}" ; do
bf-debug " .. ${DN}" "proxy/request"
request "${DN}"
done
Expand Down
2 changes: 1 addition & 1 deletion overlay/usr/lib/bf/proxy/update
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ bf-done "proxy/update"

bf-echo "Updating pem files..." "proxy/update"
create-pem ${PROXY_URI}
for DN in "${!DOMAINS[@]}" ; do create-pem "${DN}" ; done
for DN in "${DOMAINS[@]}" ; do create-pem "${DN}" ; done
bf-done "proxy/update"
17 changes: 17 additions & 0 deletions ssl-conf-sample.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"$schema": "https://raw.githubusercontent.com/bfren/docker-nginx-proxy/main/ssl-conf-schema.json",
"domains": [
{
"primary": "example.com",
"upstream": "http://example:5000",
"aliases": [ "www.example.com", "ex.com", "www.ex.com" ],
"custom": true
},
{
"primary": "test.com",
"upstream": "http://test",
"aliases": [ "www.test.com", "fred.co.uk" ],
"custom": false
}
]
}
Loading