reverse-proxy-frontend/nginx/configure-nginx.sh

34 lines
1.3 KiB
Bash

#!/bin/sh
# Configure nginx.conf based on APP_SUBFOLDER environment variable
# This script generates the appropriate nginx configuration for SPA deployments
TEMPLATE_FILE="/tmp/nginx.conf.template"
OUTPUT_FILE="/etc/nginx/nginx.conf"
if [ -n "$APP_SUBFOLDER" ]; then
echo "Configuring nginx for subfolder deployment: /$APP_SUBFOLDER/"
# Generate location block for subfolder with proper static assets handling
SUBFOLDER_CONFIG=" # Subfolder-specific configuration for /$APP_SUBFOLDER/
location /$APP_SUBFOLDER/ {
# Handle static assets in subfolder
location ~* /$APP_SUBFOLDER/.*\.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|json)$ {
expires 1y;
add_header Cache-Control \"public, immutable\";
try_files \$uri =404;
}
# SPA routing for subfolder
try_files \$uri \$uri/ /$APP_SUBFOLDER/index.html;
}"
# Replace placeholder with subfolder configuration
sed "s| # SUBFOLDER_PLACEHOLDER|$SUBFOLDER_CONFIG|g" "$TEMPLATE_FILE" > "$OUTPUT_FILE"
else
echo "Configuring nginx for root deployment"
# Remove placeholder for root deployment
sed "s| # SUBFOLDER_PLACEHOLDER||g" "$TEMPLATE_FILE" > "$OUTPUT_FILE"
fi
echo "Nginx configuration generated successfully"