Skip to content

Commit

Permalink
Tweak: Switched to docker-compose v3 syntax
Browse files Browse the repository at this point in the history
Tweak: Now using latest versions of docker-gen and companion
Tweak: Now using nginx image with mozilla's boilerplate config
Add: Readme
  • Loading branch information
fatk committed Jun 19, 2019
1 parent 4561b16 commit bda229c
Show file tree
Hide file tree
Showing 7 changed files with 222 additions and 240 deletions.
20 changes: 14 additions & 6 deletions nginx-proxy/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,19 @@ Thumbs.db
.idea/

### nginx-proxy
volumes/certs/*
!volumes/certs/.gitkeep
volumes/nginx/certs/*
!volumes/nginx/certs/.gitkeep

volumes/conf.d/*
!volumes/conf.d/.gitkeep
volumes/nginx/conf.d/*
!volumes/nginx/conf.d/.gitkeep

volumes/vhost.d/*
!volumes/vhost.d/.gitkeep
volumes/nginx/vhost.d/*
!volumes/nginx/vhost.d/.gitkeep

volumes/nginx/html/*
!volumes/nginx/html/.gitkeep

volumes/nginx/htpasswd/*
!volumes/nginx/htpasswd/.gitkeep

.env
46 changes: 46 additions & 0 deletions nginx-proxy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Pixelcloud nginx-proxy

This docker-based service uses [nginx-proxy](https://github.com/jwilder/nginx-proxy), [docker-gen](https://github.com/jwilder/docker-gen) and [docker-letsencrypt-nginx-proxy-companion](https://github.com/JrCs/docker-letsencrypt-nginx-proxy-companion).

## Description

Based on nginx-proxy, this service uses nginx (modified with config inspired from mozilla's boilerplate) and monitors other docker services having ``VIRTUAL_HOST`` environment variable to automatically proxy them.

Moreover, if said services also have ``LETSENCRYPT_HOST`` variable, it will automatically generate a Let's Encrypt SSL certificate, provided the requirements are met.

## Usage

### Environment Variables


#### Ports

You should create a ``.env`` file, located in nginx-proxy's directory root and declare the necessary variables needed in ``docker-compose.yml``

Production example:

```
HTTP_PORT=80
HTTPS_PORT=443
```

Development example:

```
HTTP_PORT=8080:80
HTTPS_PORT=8443:443
```

#### no-www

If the variable ``WWW`` is set to ``no-www`` inside your proxied service, nginx-proxy will automatically create a www.domain.com to domain.com redirection. You should add www.domain.com to ``LETSENCRYPT_HOST`` variable to get an SSL certificate as well.

#### ACME CA

By default, this spin of nginx-proxy ships with the staging version of Let's Encrypt service enabled.

To switch to production certificates, remove or comment this line in ``docker-compose.yml``

```
ACME_CA_URI: https://acme-staging.api.letsencrypt.org/directory
```
87 changes: 51 additions & 36 deletions nginx-proxy/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,54 +1,69 @@
version: "2"
version: '3'

services:
nginx:
image: pixelfordinner/nginx
container_name: pixelcloud-nginx_proxy-nginx
nginx-web:
image: pixelfordinner/nginx:test
labels:
com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy: "true"
container_name: app-pixelcloud-nginx_proxy-nginx
restart: unless-stopped
ports:
- "80:80"
- "443:443"
- '${HTTP_PORT}'
- '${HTTPS_PORT}'
volumes:
- "./volumes/conf.d:/etc/nginx/conf.d:ro"
- "./volumes/vhost.d:/etc/nginx/vhost.d:ro"
- "./volumes/certs:/etc/nginx/certs:ro"
- "/usr/share/nginx/html"
- ./volumes/nginx/conf.d:/etc/nginx/conf.d:ro
- ./volumes/nginx/vhost.d:/etc/nginx/vhost.d:ro
- ./volumes/nginx/certs:/etc/nginx/certs:ro
- ./volumes/nginx/htpasswd:/etc/nginx/htpasswd:ro
- ./volumes/nginx/html:/usr/share/nginx/html:ro
networks:
- proxy-tier
docker-gen:
image: jwilder/docker-gen:0.7.3
container_name: pixelcloud-nginx_proxy-docker_gen
logging:
options:
max-size: '4m'
max-file: '10'

nginx-gen:
image: jwilder/docker-gen
command: -notify-sighup app-pixelcloud-nginx_proxy-nginx -watch -wait 5s:30s /etc/docker-gen/templates/nginx.tmpl /etc/nginx/conf.d/default.conf
container_name: app-pixelcloud-nginx_proxy-nginx_gen
restart: unless-stopped
depends_on:
- nginx
volumes_from:
- nginx
volumes:
- "/var/run/docker.sock:/tmp/docker.sock:ro"
- "./data/templates:/etc/docker-gen/templates:ro"
- "./volumes/conf.d:/etc/nginx/conf.d:rw"
- ./volumes/nginx/conf.d:/etc/nginx/conf.d
- ./volumes/nginx/vhost.d:/etc/nginx/vhost.d
- ./volumes/nginx/certs:/etc/nginx/certs:ro
- ./volumes/nginx/htpasswd:/etc/nginx/htpasswd:ro
- /var/run/docker.sock:/tmp/docker.sock:ro
- ./volumes/docker-gen/templates/nginx.tmpl:/etc/docker-gen/templates/nginx.tmpl:ro
networks:
- proxy-tier
entrypoint: /usr/local/bin/docker-gen -notify-sighup pixelcloud-nginx_proxy-nginx -watch -wait 5s:30s /etc/docker-gen/templates/nginx.tmpl /etc/nginx/conf.d/default.conf
lets-encrypt-companion:
image: jrcs/letsencrypt-nginx-proxy-companion:v1.6
container_name: pixelcloud-nginx_proxy-lets_encrypt
logging:
options:
max-size: '4m'
max-file: '10'

nginx-letsencrypt:
image: jrcs/letsencrypt-nginx-proxy-companion
container_name: app-pixelcloud-nginx_proxy-letsencrypt
restart: unless-stopped
depends_on:
- nginx
- docker-gen
volumes_from:
- nginx
volumes:
- "/var/run/docker.sock:/var/run/docker.sock:ro"
- "./volumes/vhost.d:/etc/nginx/vhost.d:rw"
- "./volumes/certs:/etc/nginx/certs:rw"
- ./volumes/nginx/conf.d:/etc/nginx/conf.d
- ./volumes/nginx/vhost.d:/etc/nginx/vhost.d
- ./volumes/nginx/html:/usr/share/nginx/html
- ./volumes/nginx/certs:/etc/nginx/certs:rw
- /var/run/docker.sock:/var/run/docker.sock:ro
environment:
- "NGINX_DOCKER_GEN_CONTAINER=pixelcloud-nginx_proxy-docker_gen"
# - "ACME_CA_URI=https://acme-staging.api.letsencrypt.org/directory"
# - "DEBUG=true"
NGINX_DOCKER_GEN_CONTAINER: app-pixelcloud-nginx_proxy-nginx_gen
NGINX_PROXY_CONTAINER: app-pixelcloud-nginx_proxy-nginx
ACME_CA_URI: https://acme-staging.api.letsencrypt.org/directory
networks:
- proxy-tier
logging:
options:
max-size: '4m'
max-file: '10'

networks:
proxy-tier:
external:
name: "nginx-proxy"
name: nginx-proxy
Loading

0 comments on commit bda229c

Please sign in to comment.