robertbruno/nginx-docker

By robertbruno

Updated 3 months ago

Custom nginx docker + certbot && aws cli

Image
0

351

robertbruno/nginx-docker repository overview

Nginx docker

This project maintains an nginx docker image to cover basic needs, such as a load balancer or distributed proxy pass for:

  • Expose services and applications based on their domain names.
  • Manage multiple domains (if necessary). Similar to "virtual hosts".
  • Enable HTTPS and automatically generate certificates (including renewals) with Let's Encrypt.
  • Add HTTP Basic Auth for any services you need to protect that don't have their own security, etc.

Run

docker run --rm --name  nginx -p 80:80 -p 443:443 \
    -e  DOMAIN=dominio.com \
    nginx-docker

Check it

  • Check if the stack was deployed with:
docker stack ps nginx

Logs

You can consult Nginx logs by running the following command line on any swarm cluster node:

docker logs -f  --tail 100 nginx

Utils

Inside the resources/utils folder there are several files that will help you configure different features in nginx, for example:

  • gzip It has the necessary instructions to enable gzip compression on the indicated domain.
  • host Allows you to enable the replication of certain headers such as the host.

Webhookd

A very simple webhook server to launch shell scripts.

In this image we include this tool to have a simple administration and control mechanism, for example to update letsencrypt certificates, enable or disable configurations

You can use the following environment variables to configure:

  • WHD_PASSWD_FILE (default: /etc/webhookd/users.htpasswd)
  • WHD_USER
  • WHD_PASSWD

Using environment variables in nginx configuration

Out-of-the-box, nginx doesn't support environment variables inside most configuration blocks. But this image has a function, which will extract environment variables before nginx starts.

Here is an example using docker-compose.yml:

web:
  image: nginx
  volumes:
   - ./templates:/etc/nginx/templates
  ports:
   - "8080:80"
  environment:
   - NGINX_HOST=foobar.com
   - NGINX_PORT=80

By default, this function reads template files in /etc/nginx/templates/*.template and outputs the result of executing envsubst to /etc/nginx/conf.d.

So if you place templates/default.conf.template file, which contains variable references like this:

listen       ${NGINX_PORT};

outputs to /etc/nginx/conf.d/default.conf like this:

listen       80;

Directory which contains template files by default is /etc/nginx/templates. For more info:

Tag summary

Content type

Image

Digest

sha256:e2906c5f5

Size

256 Bytes

Last updated

3 months ago

docker pull robertbruno/nginx-docker:sha256-b6b952a056300abb9f0d68bbae81486f818de549d0dfef4800664f9be8c69de9.sig