fix(staging): correct nginx upstream sed patterns for production-php
All checks were successful
Test Runner / test-basic (push) Successful in 9s
Test Runner / test-php (push) Successful in 8s
Deploy Application / deploy (push) Successful in 43s

- Add explicit sed pattern for production-php:9000 → php:9000
- Fix character class [a-f0-9_]* to [a-zA-Z0-9_-]* to match full container names
- Loop over both sites-enabled and sites-available configs
- Add fastcgi_pass replacement for production-php
This commit is contained in:
2025-11-24 22:44:43 +01:00
parent 5e74ce73a6
commit 417c7d7a7d

View File

@@ -240,20 +240,25 @@ services:
find /var/www/html.orig -mindepth 1 -maxdepth 1 ! -name "storage" -exec cp -r {} "$$GIT_TARGET_DIR/" \; 2>/dev/null || true
fi
# Fix nginx upstream configuration - sites-enabled/default overrides conf.d/default.conf
# This is critical: nginx sites-available/default uses 127.0.0.1:9000 but PHP-FPM runs in php container
if [ -f "/etc/nginx/sites-available/default" ]; then
echo "🔧 [staging-nginx] Fixing PHP-FPM upstream configuration..."
# Replace in upstream block - use php container name (as defined in docker-compose.staging.yml)
sed -i '/upstream php-upstream {/,/}/s|server 127.0.0.1:9000;|server php:9000;|g' /etc/nginx/sites-available/default || true
sed -i '/upstream php-upstream {/,/}/s|server localhost:9000;|server php:9000;|g' /etc/nginx/sites-available/default || true
# Fix nginx upstream configuration - sites-enabled/default is a symlink to sites-available/default
# This is critical: nginx config uses production-php:9000 but staging uses php container
for NGINX_CONF in /etc/nginx/sites-enabled/default /etc/nginx/sites-available/default; do
if [ -f "$$NGINX_CONF" ]; then
echo "🔧 [staging-nginx] Fixing PHP-FPM upstream in $$NGINX_CONF..."
# Replace production-php with staging php container name
sed -i 's|server production-php:9000;|server php:9000;|g' "$$NGINX_CONF" || true
# Replace localhost/127.0.0.1 references
sed -i '/upstream php-upstream {/,/}/s|server 127.0.0.1:9000;|server php:9000;|g' "$$NGINX_CONF" || true
sed -i '/upstream php-upstream {/,/}/s|server localhost:9000;|server php:9000;|g' "$$NGINX_CONF" || true
# Replace any auto-generated container names (like 5aad84af7c9e_php)
sed -i '/upstream php-upstream {/,/}/s|server [a-f0-9_]*php:9000;|server php:9000;|g' /etc/nginx/sites-available/default || true
sed -i 's|server [a-zA-Z0-9_-]*php:9000;|server php:9000;|g' "$$NGINX_CONF" || true
# Replace any direct fastcgi_pass references too
sed -i 's|fastcgi_pass 127.0.0.1:9000;|fastcgi_pass php-upstream;|g' /etc/nginx/sites-available/default || true
sed -i 's|fastcgi_pass localhost:9000;|fastcgi_pass php-upstream;|g' /etc/nginx/sites-available/default || true
echo "✅ [staging-nginx] PHP-FPM upstream fixed"
sed -i 's|fastcgi_pass 127.0.0.1:9000;|fastcgi_pass php-upstream;|g' "$$NGINX_CONF" || true
sed -i 's|fastcgi_pass localhost:9000;|fastcgi_pass php-upstream;|g' "$$NGINX_CONF" || true
sed -i 's|fastcgi_pass production-php:9000;|fastcgi_pass php-upstream;|g' "$$NGINX_CONF" || true
echo "✅ [staging-nginx] PHP-FPM upstream fixed in $$NGINX_CONF"
fi
done
# Start nginx only (no PHP-FPM, no Git clone - php container handles that)
echo "🚀 [staging-nginx] Starting nginx..."