diff --git a/frontend/Dockerfile b/frontend/Dockerfile index f2c528d..9710ac9 100644 --- a/frontend/Dockerfile +++ b/frontend/Dockerfile @@ -9,7 +9,7 @@ RUN npm run build FROM nginx:alpine COPY --from=builder /app/dist/ /usr/share/nginx/html/ -# SPA fallback: all routes to index.html -RUN printf 'server {\n listen 80;\n root /usr/share/nginx/html;\n index index.html;\n location / {\n try_files $uri $uri/ /index.html;\n }\n location /api/ {\n return 404;\n }\n}\n' > /etc/nginx/conf.d/default.conf +# Nginx config: gzip + cache + SPA fallback +COPY nginx.conf /etc/nginx/conf.d/default.conf EXPOSE 80 CMD ["nginx", "-g", "daemon off;"] diff --git a/frontend/nginx.conf b/frontend/nginx.conf new file mode 100644 index 0000000..5900922 --- /dev/null +++ b/frontend/nginx.conf @@ -0,0 +1,35 @@ +server { + listen 80; + root /usr/share/nginx/html; + index index.html; + + # Gzip compression + gzip on; + gzip_vary on; + gzip_min_length 256; + gzip_comp_level 6; + gzip_types + text/plain + text/css + text/javascript + application/javascript + application/json + application/xml + image/svg+xml; + + # Static assets with hash in filename — long cache + location /assets/ { + expires 1y; + add_header Cache-Control "public, immutable"; + } + + # SPA fallback + location / { + try_files $uri $uri/ /index.html; + add_header Cache-Control "no-cache"; + } + + location /api/ { + return 404; + } +}