From f56d53d873a2d7b39c91c790dba9a9d39741136d Mon Sep 17 00:00:00 2001 From: Michael Schiemer Date: Sun, 2 Nov 2025 02:29:12 +0100 Subject: [PATCH] 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 --- .gitea/workflows/build-image.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.gitea/workflows/build-image.yml b/.gitea/workflows/build-image.yml index a974bb1f..16188e82 100644 --- a/.gitea/workflows/build-image.yml +++ b/.gitea/workflows/build-image.yml @@ -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:"