This docker image automatic proxies requests to your docker containers
First, pull the image from docker hub
docker pull stephenafamo/docker-nginx-auto-proxy:2.1.0
Run a container
docker run --name nginx -v /path/to/my/config:/docker/config/config -p 80:80 -p 443:443 stephenafamo/docker-nginx-auto-proxy:2.1.0
The container reads a configuration file /docker/config/config
To easily manage all proxies, you should mount your own configuration file.
-v /path/to/my/config.txt:/docker/config/config
The syntax is as follows(showing all possible fields).
"myblog"
"UPSTREAM"main.stephenafamo.com|1st.stephenafamo.com weight=3|2nd.stephenafamo.com max_fails=3 fail_timeout=30s"
"UPSTREAM_OPTIONS"ip_hash|keep_alive 32"
"DOMAIN"stephenafamo.com"
"DIRECTORY"blog"
"SSL"1"
"SSL_SOURCE"letsencrypt"
"SSL_MODE"any"
"myblog"
- The only required fields are
UPSTREAMandDOMAIN - A block of configuration should be started and ended by the configuration name. This name should be unique. In the example above, the configuration name is
myblog - Neither the domain or upstream address should include the scheme
http:// UPSTREAMmust be reachable or the config will not be generated.- For load balancing, you can add multiple
UPSTREAMaddresses. Separate them with pipes. - You can add any extra parameters at the end of a single upstream server. Read this.
- The
UPSTREAM_OPTIONSare not required. Use only if you need to add extra directives to the upstream block for fine tuning. Separate directives with pipes. Read this. DOMAINcan be multiple, but should be seperated by spacesDIRECTORYis the optional path to to be proxies. For example, if you'd like to proxy onlyexample.com/blog, theblogwill be the directorySSLcan be enable by setting the parameter to1SSL_SOURCEfor now, only letsencrypt is supported. Certificates will be generated automatically. Soon, mannual configuration will be supported. To be able to re-use the generated certificates, you should mount your/etc/letsencryptfolder into the container-v /etc/letsencrypt:/etc/letsencrypt. THis only works ifSSLis1.HTTPS_ONLYIf this is set to1, then allhttprequests will be redirected tohttps
The following commands are available through the contianer.
- active_domains: Will list out the domains that have been configured
- load_config: Will re-generate configuration files and reload nginx
If set up correctly, the container will attempt to get a new certificate if there was none, or renew the certificate.
The normal letsencrypt renew command may fail. Instead, to renew certificates, run the load_config command and certificate renewal will be attempted during the process.
You should set up a cron to do this automatically e.g 30 2 * * 1 docker exec nginx load_config >> /var/log/nginx-reload.log
Load balancing with multiple containersDONEAutomatic SSL support with let's encryptDONE- Allow custom ssl certificate configuration.
Please inform me of any issues, Pull requests are appreciated.