|
1 | 1 | worker_processes auto; |
2 | | -error_log /var/log/nginx/error.log warn; |
| 2 | + |
| 3 | +# Store PID in /tmp (always writable) |
3 | 4 | pid /tmp/nginx.pid; |
4 | 5 |
|
5 | 6 | events { |
6 | 7 | worker_connections 1024; |
7 | 8 | } |
8 | 9 |
|
9 | 10 | http { |
10 | | - include /etc/nginx/mime.types; |
11 | | - default_type application/octet-stream; |
| 11 | + include /etc/nginx/mime.types; |
| 12 | + default_type application/octet-stream; |
12 | 13 |
|
13 | | - log_format main '$remote_addr - $remote_user [$time_local] "$request" ' |
14 | | - '$status $body_bytes_sent "$http_referer" ' |
15 | | - '"$http_user_agent" "$http_x_forwarded_for"'; |
| 14 | + # Disable logging to avoid permission issues |
| 15 | + access_log off; |
| 16 | + error_log /dev/stderr warn; |
16 | 17 |
|
17 | | - access_log /var/log/nginx/access.log main; |
| 18 | + # Optimize static file serving |
| 19 | + sendfile on; |
| 20 | + tcp_nopush on; |
| 21 | + tcp_nodelay on; |
| 22 | + keepalive_timeout 65; |
| 23 | + keepalive_requests 1000; |
18 | 24 |
|
19 | | - sendfile on; |
20 | | - tcp_nopush on; |
21 | | - keepalive_timeout 65; |
| 25 | + # Gzip compression for optimized delivery |
22 | 26 | gzip on; |
23 | | - gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript; |
| 27 | + gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript image/svg+xml; |
| 28 | + gzip_min_length 256; |
| 29 | + gzip_vary on; |
24 | 30 |
|
25 | 31 | server { |
26 | | - listen 8080; |
27 | | - server_name localhost; |
| 32 | + listen 8080; |
| 33 | + server_name localhost; |
| 34 | + |
| 35 | + # Root directory where React.js build files are placed |
28 | 36 | root /usr/share/nginx/html; |
29 | 37 | index index.html; |
30 | 38 |
|
31 | | - # Security headers |
32 | | - add_header X-Frame-Options "SAMEORIGIN" always; |
33 | | - add_header X-Content-Type-Options "nosniff" always; |
34 | | - add_header X-XSS-Protection "1; mode=block" always; |
35 | | - add_header Referrer-Policy "strict-origin-when-cross-origin" always; |
36 | | - |
37 | | - # SPA routing - serve index.html for all routes |
| 39 | + # Serve React.js static files with proper caching |
38 | 40 | location / { |
39 | | - try_files $uri $uri/ /index.html; |
| 41 | + try_files $uri /index.html; |
40 | 42 | } |
41 | 43 |
|
42 | | - # Cache static assets |
43 | | - location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ { |
| 44 | + # Serve static assets with long cache expiration |
| 45 | + location ~* \.(?:ico|css|js|gif|jpe?g|png|woff2?|eot|ttf|svg|map)$ { |
44 | 46 | expires 1y; |
| 47 | + access_log off; |
45 | 48 | add_header Cache-Control "public, immutable"; |
46 | 49 | } |
47 | 50 |
|
48 | | - # Health check endpoint |
49 | | - location /health { |
50 | | - access_log off; |
51 | | - return 200 "healthy\n"; |
52 | | - add_header Content-Type text/plain; |
| 51 | + # Handle React.js client-side routing |
| 52 | + location /static/ { |
| 53 | + expires 1y; |
| 54 | + add_header Cache-Control "public, immutable"; |
53 | 55 | } |
54 | 56 | } |
55 | 57 | } |
56 | | - |
|
0 commit comments