mirror of
https://dev.azure.com/tstanciu94/ReverseProxy/_git/ReverseProxy_Frontend
synced 2025-10-03 16:49:04 +03:00
Refactor nginx configuration handling for dynamic subfolder support and improve asset caching
This commit is contained in:
parent
caf38d468f
commit
4a4dc2af4f
15
Dockerfile
15
Dockerfile
@ -35,14 +35,13 @@ RUN if [ -n "$APP_SUBFOLDER" ]; then mkdir -p /usr/share/nginx/html/$APP_SUBFOLD
|
|||||||
# Copy built application
|
# Copy built application
|
||||||
COPY --from=builder /app/build /usr/share/nginx/html/${APP_SUBFOLDER}
|
COPY --from=builder /app/build /usr/share/nginx/html/${APP_SUBFOLDER}
|
||||||
|
|
||||||
# Copy and configure nginx
|
# Copy nginx configuration files
|
||||||
COPY nginx.conf /tmp/nginx.conf.template
|
COPY nginx/nginx.conf /tmp/nginx.conf.template
|
||||||
# Generate nginx.conf with correct subfolder path
|
COPY nginx/configure-nginx.sh /usr/local/bin/configure-nginx.sh
|
||||||
RUN if [ -n "$APP_SUBFOLDER" ]; then \
|
RUN chmod +x /usr/local/bin/configure-nginx.sh
|
||||||
sed "s|# SUBFOLDER_PLACEHOLDER|location /$APP_SUBFOLDER/ { try_files \$uri \$uri/ /$APP_SUBFOLDER/index.html; }|g" /tmp/nginx.conf.template > /etc/nginx/nginx.conf; \
|
|
||||||
else \
|
# Generate nginx.conf with correct subfolder configuration
|
||||||
sed "s|# SUBFOLDER_PLACEHOLDER||g" /tmp/nginx.conf.template > /etc/nginx/nginx.conf; \
|
RUN /usr/local/bin/configure-nginx.sh
|
||||||
fi
|
|
||||||
|
|
||||||
# Add environment variables
|
# Add environment variables
|
||||||
ENV Author="Tudor Stanciu"
|
ENV Author="Tudor Stanciu"
|
||||||
|
34
nginx/configure-nginx.sh
Normal file
34
nginx/configure-nginx.sh
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
#!/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"
|
Loading…
x
Reference in New Issue
Block a user