Skip to content

Commit

Permalink
Example of file-based configuration added.
Browse files Browse the repository at this point in the history
  • Loading branch information
patbec committed Aug 14, 2023
1 parent 3c37b69 commit 0534e7b
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 14 deletions.
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,22 +86,24 @@ Raise both types of errors:
- Request the non-existent `http://web.localhost/sample` page to display an service error.
- Request the unknown subdomain `http://sample.localhost` to get an router error.

## Example
## Examples

You can find two complete examples in the `docs/samples` folder.
You can find three complete examples in the `docs/samples` folder.

The file [docker-compose.prod.yml](docs/samples/docker-compose.prod.yml) contains the source from the screenshot:
The file [docker-compose.prod.yml](docs/samples/docker/docker-compose.prod.yml) contains the source from the screenshot:
```shell
cd docs/samples
cd docs/samples/docker
docker compose -f docker-compose.prod.yml up
```

The file [docker-compose.dev.yml](docs/samples/docker-compose.dev.yml) rebuilds the container and includes local changes from the template or configuration file:
The file [docker-compose.dev.yml](docs/samples/docker/docker-compose.dev.yml) rebuilds the container and includes local changes from the template or configuration file:
```shell
cd docs/samples
cd docs/samples/docker
docker compose -f docker-compose.dev.yml up --build
```

The file [config.yml](docs/samples/file/config.yml) and [traefik.yml](docs/samples/file/traefik.yml) are an alternative for non-Docker environments. The default search path for this type of config file is `/etc/traefik/`, [see here for more information.](https://doc.traefik.io/traefik/getting-started/configuration-overview/#configuration-file)

## Configuration

The following environment variables are required and will be inserted into the template. Define these in your `docker-compose.yml` file.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ services:
traefik.enable: true
traefik.http.routers.nginx.rule: Host(`web.localhost`)
traefik.http.routers.nginx.entrypoints: web
traefik.http.routers.nginx.middlewares: error-pages-middleware
traefik.http.routers.nginx.middlewares: exceptions
error-pages:
container_name: error-pages
build: ../
Expand All @@ -40,9 +40,9 @@ services:
traefik.enable: true
traefik.http.services.error-pages-service.loadbalancer.server.port: 8090

traefik.http.middlewares.error-pages-middleware.errors.status: 400-599
traefik.http.middlewares.error-pages-middleware.errors.service: error-pages-service
traefik.http.middlewares.error-pages-middleware.errors.query: /{status}.html
traefik.http.middlewares.exceptions.errors.status: 400-599
traefik.http.middlewares.exceptions.errors.service: error-pages-service
traefik.http.middlewares.exceptions.errors.query: /{status}.html

traefik.http.routers.error-pages-routers.rule: HostRegexp(`{host:.+}`)
traefik.http.routers.error-pages-routers.priority: 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ services:
traefik.enable: true
traefik.http.routers.nginx.rule: Host(`web.localhost`)
traefik.http.routers.nginx.entrypoints: web
traefik.http.routers.nginx.middlewares: error-pages-middleware
traefik.http.routers.nginx.middlewares: exceptions
error-pages:
container_name: error-pages
image: "ghcr.io/patbec/traefik-error-pages:latest"
Expand All @@ -40,9 +40,9 @@ services:
traefik.enable: true
traefik.http.services.error-pages-service.loadbalancer.server.port: 8090

traefik.http.middlewares.error-pages-middleware.errors.status: 400-599
traefik.http.middlewares.error-pages-middleware.errors.service: error-pages-service
traefik.http.middlewares.error-pages-middleware.errors.query: /{status}.html
traefik.http.middlewares.exceptions.errors.status: 400-599
traefik.http.middlewares.exceptions.errors.service: error-pages-service
traefik.http.middlewares.exceptions.errors.query: /{status}.html

traefik.http.routers.error-pages-routers.rule: HostRegexp(`{host:.+}`)
traefik.http.routers.error-pages-routers.priority: 1
Expand Down
36 changes: 36 additions & 0 deletions docs/samples/file/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
http:
routers:
nginx:
rule: Host(`web.localhost`)
service: service-nginx
middlewares:
- error-pages-middleware
entrypoints:
- web

error-pages:
rule: HostRegexp(`{host:.+}`)
priority: 1
service: exceptions
entryPoints:
- web

services:
service-nginx:
loadbalancer:
servers:
- url: http://<your-ip>:80

service-error-pages:
loadbalancer:
servers:
- url: http://<your-ip>:8090

middlewares:
# Handle service exceptions.
exceptions:
errors:
status:
- "400-599"
service: service-error-pages
query: "/{status}.html"
33 changes: 33 additions & 0 deletions docs/samples/file/traefik.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
log:
level: DEBUG

global:
checkNewVersion: false
sendAnonymousUsage: false

# certificatesResolvers:
# myResolver:
# acme:
# tlsChallenge: {}
# email: [email protected]
# storage: /<your-path>/acme.json

providers:
file:
filename: /<your-path>/config.yml
watch: true

entryPoints:
web:
address: ":80"
# http:
# redirections:
# entryPoint:
# to: websecure
# scheme: gttps
# permanent: true
# websecure:
# address: ":443"
# http:
# tls:
# certResolver: myResolver

0 comments on commit 0534e7b

Please sign in to comment.