brennan revised this gist 1 month ago. Go to revision
1 file changed, 1 insertion, 1 deletion
bookwrym-fix.md
| @@ -6,7 +6,7 @@ The fix is to add a small nginx container between Caddy and Gunicorn. nginx serv | |||
| 6 | 6 | ||
| 7 | 7 | ## 1. Add the nginx config | |
| 8 | 8 | ||
| 9 | - | Create nginx-books/nginx.conf next to your docker-compose.yml]: | |
| 9 | + | Create nginx-books/nginx.conf next to your docker-compose.yml: | |
| 10 | 10 | ||
| 11 | 11 | ```nginx | |
| 12 | 12 | upstream bookwyrm { | |
brennan revised this gist 1 month ago. Go to revision
1 file changed, 78 insertions
bookwrym-fix.md(file created)
| @@ -0,0 +1,78 @@ | |||
| 1 | + | # BookWyrm + Caddy: Static Files Fix | |
| 2 | + | ||
| 3 | + | **Caddy is proxying directly to Gunicorn**, which doesn't serve static files. It returns HTML for every `/static/` request, and the browser blocks it due to MIME type mismatch. | |
| 4 | + | ||
| 5 | + | The fix is to add a small nginx container between Caddy and Gunicorn. nginx serves `/static/` and `/images/` straight from the Docker volumes, and passes everything else to Gunicorn. | |
| 6 | + | ||
| 7 | + | ## 1. Add the nginx config | |
| 8 | + | ||
| 9 | + | Create nginx-books/nginx.conf next to your docker-compose.yml]: | |
| 10 | + | ||
| 11 | + | ```nginx | |
| 12 | + | upstream bookwyrm { | |
| 13 | + | server bookwyrm-web:8000; | |
| 14 | + | } | |
| 15 | + | ||
| 16 | + | server { | |
| 17 | + | listen 80; | |
| 18 | + | client_max_body_size 10M; | |
| 19 | + | ||
| 20 | + | location /static/ { | |
| 21 | + | alias /app/static/; | |
| 22 | + | } | |
| 23 | + | ||
| 24 | + | location /images/ { | |
| 25 | + | alias /app/images/; | |
| 26 | + | } | |
| 27 | + | ||
| 28 | + | location / { | |
| 29 | + | proxy_pass http://bookwyrm; | |
| 30 | + | proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
| 31 | + | proxy_set_header Host $host; | |
| 32 | + | proxy_set_header X-Forwarded-Proto https; | |
| 33 | + | proxy_redirect off; | |
| 34 | + | } | |
| 35 | + | } | |
| 36 | + | ``` | |
| 37 | + | ||
| 38 | + | ## 2. Add the nginx service to docker-compose.yml | |
| 39 | + | ||
| 40 | + | ```yaml | |
| 41 | + | bookwyrm-nginx: | |
| 42 | + | image: nginx:alpine | |
| 43 | + | restart: unless-stopped | |
| 44 | + | depends_on: | |
| 45 | + | - bookwyrm-web | |
| 46 | + | volumes: | |
| 47 | + | - ./nginx-books/nginx.conf:/etc/nginx/conf.d/default.conf:ro | |
| 48 | + | - bookwyrm_static:/app/static:ro | |
| 49 | + | - bookwyrm_media:/app/images:ro | |
| 50 | + | ``` | |
| 51 | + | ||
| 52 | + | Make sure it's on the same Docker network as your other BookWyrm containers. | |
| 53 | + | ||
| 54 | + | ## 3. Update Caddy to point at nginx, not Gunicorn | |
| 55 | + | ||
| 56 | + | ``` | |
| 57 | + | books.yourdomain.com { | |
| 58 | + | reverse_proxy bookwyrm-nginx:80 | |
| 59 | + | } | |
| 60 | + | ``` | |
| 61 | + | ||
| 62 | + | Instead of `bookwyrm-web:8000`. | |
| 63 | + | ||
| 64 | + | ## 4. Restart everything | |
| 65 | + | ||
| 66 | + | ```bash | |
| 67 | + | docker compose up -d | |
| 68 | + | ``` | |
| 69 | + | ||
| 70 | + | If Caddy seems to be ignoring the new config, `caddy reload` doesn't always apply changes. Do a full restart instead: | |
| 71 | + | ||
| 72 | + | ```bash | |
| 73 | + | docker compose up -d --force-recreate caddy | |
| 74 | + | ``` | |
| 75 | + | ||
| 76 | + | ## One gotcha: celery-beat needs EMAIL_HOST | |
| 77 | + | ||
| 78 | + | BookWyrm's settings require `EMAIL_HOST` even for containers that never send email (like `celery-beat`). Pass the full email env block to all BookWyrm containers or beat will crash on startup. | |