# ============================================================================= # Configuration NGINX PRODUCTION pour pra-geo (IN4) # Date: 2025-10-07 # Environnement: PRODUCTION # Server: Container pra-geo (13.23.34.43) # Port: 80 uniquement (HTTP) # SSL/HTTPS: Géré par le reverse proxy NGINX sur le host IN4 # ============================================================================= # Site principal (web statique) server { listen 80; server_name geosector.fr; root /var/www/geosector/web; index index.html; # Logs PRODUCTION access_log /var/log/nginx/geosector-web_access.log combined; error_log /var/log/nginx/geosector-web_error.log warn; location / { try_files $uri $uri/ /index.html; } # Assets statiques avec cache agressif location ~* \.(jpg|jpeg|png|gif|ico|svg|webp|css|js|woff|woff2|ttf|eot)$ { expires 1y; add_header Cache-Control "public, immutable"; access_log off; } # Protection des fichiers sensibles location ~ /\.(?!well-known) { deny all; access_log off; log_not_found off; } } # ============================================================================= # APPLICATION FLUTTER + API PHP # ============================================================================= server { listen 80; server_name app3.geosector.fr; # Logs PRODUCTION access_log /var/log/nginx/pra-app_access.log combined; error_log /var/log/nginx/pra-app_error.log warn; # Récupérer le vrai IP du client depuis le reverse proxy set_real_ip_from 13.23.34.0/24; # Réseau Incus set_real_ip_from 51.159.7.190; # IP publique IN4 real_ip_header X-Forwarded-For; real_ip_recursive on; # Taille maximale des uploads (pour les logos, exports, etc.) client_max_body_size 10M; client_body_buffer_size 128k; # Timeouts optimisés pour PRODUCTION client_body_timeout 30s; client_header_timeout 30s; send_timeout 60s; # ============================================================================= # APPLICATION FLUTTER (contenu statique) # ============================================================================= location / { root /var/www/geosector/app; index index.html; try_files $uri $uri/ /index.html; # Cache intelligent pour PRODUCTION # HTML : pas de cache (pour déploiements) location ~* \.html$ { expires -1; add_header Cache-Control "no-cache, no-store, must-revalidate"; } # Assets Flutter (JS, CSS, fonts) avec hash : cache agressif location ~* \.(js|css|woff|woff2|ttf|eot)$ { expires 1y; add_header Cache-Control "public, immutable"; access_log off; } # Images : cache longue durée location ~* \.(jpg|jpeg|png|gif|ico|svg|webp)$ { expires 30d; add_header Cache-Control "public"; access_log off; } } # ============================================================================= # API PHP (RESTful) # ============================================================================= location /api/ { root /var/www/geosector; # CORS - Le reverse proxy IN4 ajoute déjà les headers CORS # On les ajoute ici pour les requêtes internes si besoin # Cache API : pas de cache (données dynamiques) add_header Cache-Control "no-store, no-cache, must-revalidate" always; add_header Pragma "no-cache" always; add_header Expires "0" always; # Rewrite vers index.php try_files $uri $uri/ /api/index.php$is_args$args; # Traitement PHP location ~ ^/api/(.+\.php)$ { root /var/www/geosector; # FastCGI PHP-FPM fastcgi_pass unix:/run/php-fpm83/php-fpm.sock; fastcgi_index index.php; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $request_filename; # Variable d'environnement PRODUCTION fastcgi_param APP_ENV "production"; fastcgi_param SERVER_NAME "app3.geosector.fr"; # Headers transmis à PHP (viennent du reverse proxy) fastcgi_param HTTP_X_REAL_IP $http_x_real_ip; fastcgi_param HTTP_X_FORWARDED_FOR $http_x_forwarded_for; fastcgi_param HTTP_X_FORWARDED_PROTO $http_x_forwarded_proto; fastcgi_param HTTPS $http_x_forwarded_proto; # Timeouts pour opérations longues (sync, exports) fastcgi_read_timeout 300; fastcgi_send_timeout 300; fastcgi_connect_timeout 60; # Buffers optimisés fastcgi_buffer_size 128k; fastcgi_buffers 256 16k; fastcgi_busy_buffers_size 256k; fastcgi_temp_file_write_size 256k; } } # ============================================================================= # UPLOADS ET MÉDIAS # ============================================================================= location /api/uploads/ { alias /var/www/geosector/api/uploads/; # Cache pour les médias uploadés expires 7d; add_header Cache-Control "public"; # Sécurité : empêcher l'exécution de scripts location ~ \.(php|phtml|php3|php4|php5|phps)$ { deny all; } } # ============================================================================= # SÉCURITÉ # ============================================================================= # Bloquer l'accès aux fichiers sensibles location ~ /\.(?!well-known) { deny all; access_log off; log_not_found off; } # Bloquer l'accès aux fichiers de configuration location ~* \.(env|sql|bak|backup|swp|config|conf|ini|log)$ { deny all; access_log off; log_not_found off; } # Protection contre les requêtes invalides if ($request_method !~ ^(GET|HEAD|POST|PUT|DELETE|PATCH|OPTIONS)$) { return 405; } # ============================================================================= # MONITORING # ============================================================================= # Endpoint de health check (accessible en interne) location = /nginx-health { access_log off; allow 127.0.0.1; allow 13.23.34.0/24; # Réseau interne Incus deny all; return 200 "healthy\n"; add_header Content-Type text/plain; } }