|
1 | | -server { |
2 | | - listen 8080; |
3 | | - server_name localhost; |
| 1 | +events { |
| 2 | + worker_connections 1024; |
| 3 | +} |
4 | 4 |
|
5 | | - root /usr/share/nginx/html; |
6 | | - index index.html; |
| 5 | +http { |
| 6 | + include /etc/nginx/mime.types; |
| 7 | + default_type application/octet-stream; |
7 | 8 |
|
8 | | - location / { |
9 | | - # Handles Angular routing |
10 | | - try_files $uri $uri/ /index.html; |
11 | | - } |
| 9 | + sendfile on; |
| 10 | + keepalive_timeout 65; |
12 | 11 |
|
13 | | - # Optional: Static file caching |
14 | | - location ~* \.(?:ico|css|js|gif|jpg|jpeg|png|svg|woff|woff2|ttf|otf|eot|ttf|ttc|map)$ { |
15 | | - expires 6M; |
16 | | - access_log off; |
17 | | - add_header Cache-Control "public"; |
18 | | - } |
| 12 | + server { |
| 13 | + listen 8080; |
| 14 | + server_name localhost; |
| 15 | + |
| 16 | + # Disable automatic trailing slash redirects |
| 17 | + server_name_in_redirect off; |
| 18 | + port_in_redirect off; |
| 19 | + |
| 20 | + root /usr/share/nginx/html; |
| 21 | + index index.html; |
19 | 22 |
|
20 | | - error_page 404 /index.html; |
| 23 | + location / { |
| 24 | + # Handles Angular routing |
| 25 | + try_files $uri $uri/ /index.html; |
| 26 | + |
| 27 | + # Additional headers for SPA |
| 28 | + add_header Cache-Control "no-cache, no-store, must-revalidate"; |
| 29 | + add_header Pragma "no-cache"; |
| 30 | + add_header Expires "0"; |
| 31 | + } |
| 32 | + |
| 33 | + # Handle Angular routes without trailing slash |
| 34 | + location ~ ^/([^/]+)$ { |
| 35 | + try_files $uri $uri/ /index.html; |
| 36 | + } |
| 37 | + |
| 38 | + # Optional: Static file caching |
| 39 | + location ~* \.(?:ico|css|js|gif|jpg|jpeg|png|svg|woff|woff2|ttf|otf|eot|ttf|ttc|map)$ { |
| 40 | + expires 6M; |
| 41 | + access_log off; |
| 42 | + add_header Cache-Control "public"; |
| 43 | + } |
| 44 | + |
| 45 | + error_page 404 /index.html; |
| 46 | + } |
21 | 47 | } |
0 commit comments