Redbase daemon to use with Traefik plugin, redirect based on records in an SQLite database.
1.2K
Description: Creates a Redbase daemon to be used with Traefik plugin https://github.com/vtacquet/redbase-plugin. The daemon will create a new redbase.db file in the REDBASE_DB_PATH (default /db) if it does not exist, it will also create a "redirect" table + index and a "log" table, you can insert records via the PHPLiteAdmin page on port 8822 or directly (into redbase.db) with another SQLite client after the database has been created. Redbase will listen for requests from the redbase-plugin on REDBASE_URL (default :9922, you can specify IP:PORT or just :PORT).
redirect table - Record structure for the "redirect" table is "from_url" - text, "to_url" text, "priority" - number with only values 1-9 allowed. A "redirect" record has a combined "from_url" + "priority" constraint. 1 is highest priority, 9 is lowest. You could insert the same record with 2 different priorities and when the main site (eg. with priority 5) is down, update that record to priority 9 so the next record in line (eg. with priority 6) takes over.
| from_url | to_url | priority |
| (text) | (text) | (1-9) |
| -------------------------------------- | ---------------------------------------------- | -------- |
| https://my-server.com/go/google | https://www.google.com | 5 |
| https://my-server.com/go/google | https://www2.google.com | 6 |
| https://my-server.com/go/login | https://somewhere-else.com/php/login.php | 5 |
log table - Record structure for the "log" table is "from_url" - text, "count" - number, "last_update" - timestamp. The "log" table will show all requests, even if they do not exist in the "redirect" table.
| from_url | count | last_update |
| (text) | (number) | (timestamp) |
| -------------------------------------- | ---------- | ------------------- |
| https://my-server.com/go/google | 14 | 2022-03-29 15:45:37 |
| https://my-server.com/go/login | 5 | 2022-03-29 12:12:11 |
| https://my-server.com/go/junk | 3 | 2022-02-29 04:42:54 |
When a request is made from the redbase-plugin and there is no matching record in the "redirect" table, the daemon will reply with "@default", this will allow the redbase-plugin to fall back to its "defaulturl".
PHPLITEADMIN_PASSWORD=admin - to authenticate on the 8822 port with PHPLiteAdmin
REDBASE_DB_PATH=/db - location of the redbase.db SQLite database - use a volume
REDBASE_URL=:9922 - port for the redbase-plugin to connect to
docker-compose example:
redbase:
hostname: redbase
container_name: redbase
image: vtacquet/redbase:latest
restart: unless-stopped
volumes:
- /etc/localtime:/etc/localtime:ro
- /opt/docker/redbase/db:/db
ports:
- "8822:8822"
- "9922:9922"
environment:
- TZ=Europe/Brussels
- PHPLITEADMIN_PASSWORD=admin
- REDBASE_DB_PATH=/db
- REDBASE_URL=:9922
logging:
options:
max-size: 10m
traefik:
hostname: traefik
container_name: traefik
image: traefik:latest
restart: always
volumes:
- /etc/localtime:/etc/localtime:ro
- /opt/docker/traefik/config:/etc/traefik
- /opt/docker/traefik/data:/data
- /opt/docker/traefik/log:/var/log
- /opt/docker/traefik/plugins:/plugins-local/src/github.com
environment:
- TZ=Europe/Brussels
/opt/docker/traefik/config/traefik.yml
...
experimental:
plugins:
redbase:
moduleName: github.com/vtacquet/redbase-plugin
version: "v0.1.0"
...
/opt/docker/traefik/config/http.yml
http:
routers:
my-site:
entrypoints: "in443
tls:
certresolver: "letsencrypt""
rule: "Host(`my-server.com`) && PathPrefix(`/go`)"
middlewares:
- redbase
service: noop@internal
middlewares:
redbase:
plugin:
redbase:
redbaseurl: "redbase:9922"
defaulturl: "https://www.tacquet.be"
Content type
Image
Digest
Size
28.3 MB
Last updated
over 4 years ago
docker pull vtacquet/redbase