ok first i think i know about this issue where my css file is using something http instead of https in the href but that is generated by something like this in my index.html. Note that i am using traefik for reverse proxy and having letsencrypt to handle https cert
i am following this guide https://testdriven.io/blog/fastapi-docker-traefik/#traefik
while i change the codes inside for fastapi for my own but the rest such as traefik and docker etc is same
<link href="{{ url_for('static', path='/css/style.css') }}" rel="stylesheet">
as for my main.py
app.mount(
"/static",
StaticFiles(directory=settings.ROOT_DIR / "static"),
name="static",
)
so currently, after the rendering, i found out that my css file is loading from http instead of https. Is there any way to fix this to make it https instead of http?
also for my file structure is something like this
app folder
|main.py
html folder
|index.html
static folder
|css folder
|style.css
my traefik configuration traefik.toml
# traefik.prod.toml
[entryPoints]
[entryPoints.web]
address = ":80"
[entryPoints.web.http]
[entryPoints.web.http.redirections]
[entryPoints.web.http.redirections.entryPoint]
to = "websecure"
scheme = "https"
[entryPoints.websecure]
address = ":443"
[accessLog]
[api]
dashboard = true
[providers]
[providers.docker]
exposedByDefault = false
[certificatesResolvers.letsencrypt.acme]
email = "testtest@gmail.com"
storage = "/certificates/acme.json"
[certificatesResolvers.letsencrypt.acme.httpChallenge]
entryPoint = "web"
and my compose
# docker-compose.prod.yml
version: '3.8'
services:
web:
build:
context: .
dockerfile: Dockerfile.prod
expose:
- 80
environment:
- DATABASE_URL=$DATABASE_URL
depends_on:
- db
labels:
- "traefik.enable=true"
- "traefik.http.routers.fastapi.rule=Host(`test.domain.tk`)"
- "traefik.http.routers.fastapi.tls=true"
- "traefik.http.routers.fastapi.tls.certresolver=letsencrypt"
db:
image: postgres:13-alpine
volumes:
- postgres_data_prod:/var/lib/postgresql/data/
expose:
- 5432
environment:
- POSTGRES_USER=$POSTGRES_USER
- POSTGRES_PASSWORD=$POSTGRES_PASSWORD
- POSTGRES_DB=$POSTGRES_DB
traefik:
build:
context: .
dockerfile: Dockerfile.traefik
ports:
- 80:80
- 443:443
volumes:
- "/var/run/docker.sock:/var/run/docker.sock:ro"
- "./traefik-public-certificates:/certificates"
labels:
- "traefik.enable=true"
- "traefik.http.routers.dashboard.rule=Host(`dashboard.domain.tk`)"
- "traefik.http.routers.dashboard.tls=true"
- "traefik.http.routers.dashboard.tls.certresolver=letsencrypt"
- "traefik.http.routers.dashboard.service=api@internal"
- "traefik.http.routers.dashboard.middlewares=auth"
- "traefik.http.middlewares.auth.basicauth.users=$TRAEFIK_DASHBOARD_USER:$TRAEFIK_DASHBOARD_PASSWORD"
volumes:
postgres_data_prod:
traefik-public-certificates:
my docker file
# Dockerfile.prod
FROM tiangolo/uvicorn-gunicorn:python3.8-slim
RUN apt-get update && apt-get install -y netcat
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
and i have a prestart script
# prestart.sh
echo "Waiting for postgres connection"
while ! nc -z db 5432; do
sleep 0.1
done
echo "PostgreSQL started"
exec "$@"