Added detailed troubleshooting section for the nginx configuration
issue that caused 404 errors for GIF files.
Changes:
- Added new troubleshooting subsection: 'GIFs return 404 but files exist'
- Documented the nginx regex problem and solution
- Included before/after nginx configuration examples
- Explained negative lookahead regex pattern
- Updated Docker image digest to latest version
- Added latest commit reference (bc688e5)
This helps future admins understand and debug similar nginx routing
issues where static asset caching interferes with backend proxying.
Co-Authored-By: Auggie
5.5 KiB
🎨 GIF Preview Regeneration Guide
Overview
This guide explains how to regenerate GIF preview images for all videos in the Znakovni.hr database. This is necessary after deploying to production because video files have different UUIDs than in development.
Problem
When you see 404 errors for GIF files like:
https://znakovni.matijaturk.from.hr/uploads/gifs/7-adresa-c9ce5c69-1768753308093.gif
Failed to load resource: the server responded with a status of 404
This means the GIF files don't exist on the production server because they were generated locally with different video UUIDs.
Solutions
Option 1: Web UI (Recommended) 🌐
Easiest method - no terminal access needed!
-
Deploy the latest Docker image:
docker pull git.matijaturk.from.hr/johnny2211/znakovni.hr:latest docker-compose down docker-compose up -d -
Open the regeneration tool in your browser:
https://znakovni.matijaturk.from.hr/regenerate-gifs.html -
Login as admin (if not already logged in)
-
Click the "🔄 Start GIF Regeneration" button
-
Wait for completion (may take several minutes depending on number of videos)
-
View results - The page will show:
- Total videos processed
- Number of successful GIF generations
- Number of failures (if any)
- Error messages for failed videos
-
Refresh the dictionary page to see the new GIF previews!
Option 2: Docker Environment Variable 🐳
Automatic regeneration on container startup:
-
Add to your docker-compose.yml or .env file:
environment: - REGENERATE_GIFS=true -
Restart the container:
docker-compose down docker-compose up -d -
Check logs to monitor progress:
docker-compose logs -f -
Remove the environment variable after first run to avoid regenerating on every restart
Option 3: API Endpoint 🔧
Direct API call (requires authentication):
curl -X POST https://znakovni.matijaturk.from.hr/api/terms/regenerate-all-gifs \
-H "Cookie: your-session-cookie" \
-H "Content-Type: application/json"
Response:
{
"total": 6,
"success": 6,
"failed": 0,
"errors": []
}
What Gets Created
For each video in the database, the system will:
- ✅ Extract frames from the video file
- ✅ Generate a GIF preview with these settings:
- Width: 300px (height auto-scaled)
- FPS: 10 frames per second
- Duration: 3 seconds
- Quality: High (palette-based encoding)
- ✅ Save GIF to
/uploads/gifs/directory - ✅ Create database record with
kind: 'GIF' - ✅ Delete old GIF files if they exist
Expected Results
On Dictionary Page:
- ✅ Words with videos → Animated GIF preview
- ✅ Words without videos → 📝 Emoji icon
- ✅ Words with videos but no GIF → "Nema pregleda" icon
In Admin Panel:
- ✅ Video and GIF displayed side-by-side
- ✅ "Regenerate GIF" button (🔄) for individual regeneration
- ✅ Green checkmark "✓ GIF preview dostupan"
Troubleshooting
GIFs still not showing after regeneration
- Check browser console (F12) for 404 errors
- Verify GIF files exist on server:
ls -lh /path/to/uploads/gifs/ - Check database records:
docker exec -it znakovni-app sh cd packages/backend npx tsx scripts/check-gifs.ts
Regeneration fails for some videos
- Check that video files exist in
/uploads/videos/ - Verify ffmpeg is installed in the container
- Check container logs for specific error messages
- Ensure sufficient disk space for GIF files
Permission errors
- Ensure
/uploads/gifs/directory is writable - Check file ownership and permissions
GIFs return 404 but files exist on server
This was a nginx configuration issue (fixed in commit bc688e5):
Problem: nginx regex for static assets was catching ALL .gif files, including those in /uploads/gifs/, and trying to serve them from frontend dist/ directory instead of proxying to backend.
Solution: Updated nginx.conf to exclude /uploads/ path from static asset caching:
# Before (broken):
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
expires 1y;
add_header Cache-Control "public, immutable";
}
# After (fixed):
location ~* ^/(?!uploads/).*\.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
expires 1y;
add_header Cache-Control "public, immutable";
}
The negative lookahead (?!uploads/) ensures files under /uploads/ are proxied to backend, not served as static assets.
Technical Details
- GIF Generator: Uses ffmpeg with two-pass palette optimization
- File naming: GIFs use same filename as video but with
.gifextension - Database: GIF records stored in
term_mediatable withkind='GIF' - Cleanup: Old GIF files and database records are deleted before regeneration
Maintenance
Regenerate single GIF (Admin UI)
- Go to Admin → Terms
- Click video icon (🎥) for the term
- Click "Regenerate GIF" button (🔄)
- Wait for completion
Regenerate all GIFs (after bulk video upload)
Use Option 1 (Web UI) or Option 2 (Docker env var) from above.
Last updated: 2026-01-18
Docker image: git.matijaturk.from.hr/johnny2211/znakovni.hr:latest
Digest: sha256:9d17eac2038678e8b65d54eb8a5f1b99974810f829ff414288deb849876db620
Latest commit: bc688e5 - Fix nginx configuration for GIF serving