Skip to content

Commit a80d9cf

Browse files
author
AlessGarau
committed
fix: Add nginx configuration for SPA client-side routing
- Add nginx.conf with proper SPA routing configuration - Update Dockerfile.client.prod to include nginx configuration - Fixes 404 errors when reloading pages in production
1 parent e961a88 commit a80d9cf

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

Docker/Dockerfile.client.prod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ RUN npm run build
2727

2828
FROM nginx:alpine
2929
COPY --from=build /app/dist /usr/share/nginx/html
30+
COPY Docker/nginx.conf /etc/nginx/conf.d/default.conf

Docker/nginx.conf

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
server {
2+
listen 80;
3+
listen [::]:80;
4+
server_name localhost;
5+
6+
root /usr/share/nginx/html;
7+
index index.html;
8+
9+
# Gestion des assets statiques
10+
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
11+
expires 1y;
12+
add_header Cache-Control "public, immutable";
13+
try_files $uri =404;
14+
}
15+
16+
# Fallback pour toutes les autres routes (SPA routing)
17+
location / {
18+
try_files $uri $uri/ /index.html;
19+
20+
# Headers de sécurité
21+
add_header X-Frame-Options "SAMEORIGIN" always;
22+
add_header X-Content-Type-Options "nosniff" always;
23+
add_header X-XSS-Protection "1; mode=block" always;
24+
}
25+
26+
# Gestion des erreurs
27+
error_page 404 /index.html;
28+
29+
# Santé check
30+
location /health {
31+
access_log off;
32+
return 200 "healthy\n";
33+
add_header Content-Type text/plain;
34+
}
35+
}

0 commit comments

Comments
 (0)