mirror of
https://dev.azure.com/tstanciu94/ReverseProxy/_git/ReverseProxy_Frontend
synced 2025-10-03 16:49:04 +03:00
Refactor nginx configuration handling in Dockerfile and configure-nginx.sh for improved subfolder deployment
This commit is contained in:
parent
4a4dc2af4f
commit
5ef0fe31d3
@ -35,12 +35,12 @@ RUN if [ -n "$APP_SUBFOLDER" ]; then mkdir -p /usr/share/nginx/html/$APP_SUBFOLD
|
||||
# Copy built application
|
||||
COPY --from=builder /app/build /usr/share/nginx/html/${APP_SUBFOLDER}
|
||||
|
||||
# Copy nginx configuration files
|
||||
COPY nginx/nginx.conf /tmp/nginx.conf.template
|
||||
# Copy and configure nginx
|
||||
COPY nginx/nginx.conf /etc/nginx/nginx.conf
|
||||
COPY nginx/configure-nginx.sh /usr/local/bin/configure-nginx.sh
|
||||
RUN chmod +x /usr/local/bin/configure-nginx.sh
|
||||
|
||||
# Generate nginx.conf with correct subfolder configuration
|
||||
# Configure nginx.conf based on APP_SUBFOLDER
|
||||
RUN /usr/local/bin/configure-nginx.sh
|
||||
|
||||
# Add environment variables
|
||||
|
@ -1,34 +1,33 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Configure nginx.conf based on APP_SUBFOLDER environment variable
|
||||
# This script generates the appropriate nginx configuration for SPA deployments
|
||||
# This script modifies the existing nginx.conf for subfolder deployments
|
||||
|
||||
TEMPLATE_FILE="/tmp/nginx.conf.template"
|
||||
OUTPUT_FILE="/etc/nginx/nginx.conf"
|
||||
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/"
|
||||
|
||||
# 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;
|
||||
}"
|
||||
# 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"
|
||||
|
||||
# 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"
|
||||
sed -i '/# SUBFOLDER_PLACEHOLDER/d' "$CONFIG_FILE"
|
||||
fi
|
||||
|
||||
echo "Nginx configuration generated successfully"
|
||||
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"
|
Loading…
x
Reference in New Issue
Block a user