fix: add automatic nginx upstream fix for staging 502 errors

- Add post-deployment fix in build-image.yml workflow to automatically fix nginx upstream configuration
- nginx sites-available/default uses 127.0.0.1:9000 but PHP-FPM runs in staging-app container
- Fix runs automatically after each staging deployment
- Add troubleshooting documentation for staging 502 errors
- Add Ansible playbooks for quick fix and diagnosis
This commit is contained in:
2025-11-02 02:29:12 +01:00
parent 4cec6dd8a0
commit f56d53d873

View File

@@ -990,6 +990,15 @@ jobs:
echo "🔄 Restarting staging-app to ensure all services are up-to-date..."
docker compose restart staging-app || echo "⚠️ Failed to restart staging-app"
# Fix nginx upstream configuration - critical fix for 502 errors
# sites-available/default uses 127.0.0.1:9000 but PHP-FPM runs in staging-app container
echo "🔧 Fixing nginx PHP-FPM upstream configuration (post-deploy fix)..."
sleep 5
docker compose exec -T staging-nginx sed -i '/upstream php-upstream {/,/}/s|server 127.0.0.1:9000;|server staging-app:9000;|g' /etc/nginx/sites-available/default || echo "⚠️ Upstream fix (127.0.0.1) failed"
docker compose exec -T staging-nginx sed -i '/upstream php-upstream {/,/}/s|server localhost:9000;|server staging-app:9000;|g' /etc/nginx/sites-available/default || echo "⚠️ Upstream fix (localhost) failed"
docker compose exec -T staging-nginx nginx -t && docker compose restart staging-nginx || echo "⚠️ Nginx config test or restart failed"
echo "✅ Nginx configuration fixed and reloaded"
echo "⏳ Waiting for services to stabilize..."
sleep 10
echo "📊 Container status:"