https://github.com/stafyniaksacha/strapi-traefik-https
Simple https configuration for strapi using traefik
https://github.com/stafyniaksacha/strapi-traefik-https
Last synced: 9 months ago
JSON representation
Simple https configuration for strapi using traefik
- Host: GitHub
- URL: https://github.com/stafyniaksacha/strapi-traefik-https
- Owner: stafyniaksacha
- Created: 2020-08-07T12:02:22.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-08-07T14:38:46.000Z (over 5 years ago)
- Last Synced: 2025-02-04T19:15:12.278Z (11 months ago)
- Language: Shell
- Size: 42 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# :lock: Strapi HTTPS with Traefik
Simple docker https configuration for strapi using traefik
- https://github.com/containous/traefik
- https://github.com/strapi/strapi
- https://github.com/postgres/postgres (for this example)
## :rocket: Quickstart (6 steps)
1. Clone this repository (or fork it)
```sh
git clone git@github.com:stafyniaksacha/strapi-traefik-https.git
cd ./strapi-traefik-https
```
2. Create a new Strapi project in `./strapi` folder
```sh
yarn create strapi-app strapi
```
> or copy your project to `./strapi`
> or create a symlink to your existing project to `./strapi`
> or clone a git submodule into `./strapi`
3. Add `strapi-connector-bookshelf` and `pg` packages to strapi project
```sh
cd ./strapi
yarn add strapi-connector-bookshelf pg
```
4. Update Strapi configuration
```js
// ./strapi/config/database.js
module.exports = ({ env }) => ({
defaultConnection: 'default',
connections: {
default: {
connector: 'bookshelf',
settings: {
client: 'postgres',
host: env('DATABASE_HOST', 'postgres'),
port: env.int('DATABASE_PORT', 5432),
database: env('DATABASE_NAME', 'postgresdb'),
username: env('DATABASE_USERNAME', 'postgresuser'),
password: env('DATABASE_PASSWORD', 'postgrespassword'),
},
options: {},
},
},
});
```
```js
// ./strapi/config/server.js
module.exports = ({ env }) => ({
host: env('HOST', '0.0.0.0'),
port: env.int('PORT', 1337),
url: `https://${env('STRAPI_URL', '127.0.0.1')}/`,
admin: {
auth: {
secret: env('ADMIN_JWT_SECRET'),
},
}
});
```
5. Create docker network
```sh
docker network create my-app-services
```
6. Start the whole stack
```sh
docker-compose up
```
## :tada: Access your services
**Strapi admin**: https://strapi.127.0.0.1.xip.io/admin
**Traefik dashboard**: https://traefik.127.0.0.1.xip.io/ (htpasswd auth: user/pass)
> Traefik is binded to the host network:
> using xip.io service allow us to have a wildcard dns pointing to 127.0.0.1
> You can change `./traefik/htpasswd` file to change http auth for traefik dashboard
## :arrows_counterclockwise: Development with hotreload
1. install `node_modules` from your host
```sh
yarn
```
2. start your stack with `docker-compose.dev.yml`
```sh
CURRENT_UID=$(id -u):$(id -g) docker-compose -f docker-compose.dev.yml up
```
> `CURRENT_UID` is used to bind your host user to the docker container user
> so files created inside the container or outside remain the same (no fs erros !)
## :triangular_flag_on_post: Environment variables
| Name | Default | Description |
| ------------- | ------------- | ------------- |
| HOST | `127.0.0.1.xip.io` | main host for all services |
| DOCKER_SERVICES_RESTART | `no` | docker auto restart policy, can be `always` |
| POSTGRES_DB | `postgresdb` | postgres default database name |
| DATABASE_USERNAME | `postgresuser` | postgres default user name |
| DATABASE_PASSWORD | `postgrespassword` | postgres default user password |
| ADMIN_JWT_SECRET | `jwtsecret` | strapi admin jwt token (since 3.1.x) |
## :file_folder: Create data backup
Generate a folder in `./backups` directory containing:
- strapi uploaded media `./backups/YYYYMMDD-HHmm/strapi_uploads.tar.gz`
- postgres dump `./backups/YYYYMMDD-HHmm/dump_postgres.sql`
```sh
chmod +x ./backup.sh
./backup.sh
```