#!/bin/sh # Configure nginx.conf based on APP_SUBFOLDER environment variable # This script modifies the existing nginx.conf for subfolder deployments CONFIG_FILE="/etc/nginx/nginx.conf" echo "Starting nginx configuration..." echo "APP_SUBFOLDER: $APP_SUBFOLDER" echo "Config file: $CONFIG_FILE" if [ -n "$APP_SUBFOLDER" ]; then echo "Configuring nginx for subfolder deployment: /$APP_SUBFOLDER/" # Add simple subfolder location for SPA routing (static assets already handled globally) sed -i "s|# SUBFOLDER_PLACEHOLDER| location /$APP_SUBFOLDER/ { try_files \$uri \$uri/ /$APP_SUBFOLDER/index.html; }|g" "$CONFIG_FILE" else echo "Configuring nginx for root deployment" # Remove placeholder for root deployment sed -i '/# SUBFOLDER_PLACEHOLDER/d' "$CONFIG_FILE" fi echo "Nginx configuration generated successfully" # Debug: show configured nginx.conf structure and first few lines echo "Configured nginx.conf structure:" head -10 "$CONFIG_FILE" echo "..." grep -E "^(events|http|server)" "$CONFIG_FILE" || echo "Warning: Missing main sections" # Verify file size echo "Final file size: $(wc -c < "$CONFIG_FILE") bytes"