-
Notifications
You must be signed in to change notification settings - Fork 22
/
nginix.conf
92 lines (76 loc) · 2.55 KB
/
nginix.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# server {
# listen 3000;
# server_name localhost;
# # Root directory for the exported static site
# root /usr/share/nginx/html;
# index index.html;
# # Global 404 error handling
# error_page 404 /404.html;
# # Comprehensive location blocks for routing
# location / {
# # Try to serve exact URI, then .html version, then fall back to 404 or index
# try_files $uri $uri.html $uri/ =404;
# }
# # Specific route handling with fallback to 404
# location /docs/ {
# try_files $uri $uri.html $uri/ /404.html =404;
# }
# # Dynamic route handling
# location ~ ^/([^/]+)/([^/]+)/?$ {
# try_files $uri $uri.html /404.html =404;
# }
# # Explicit 404 location to ensure it's always served
# location = /404.html {
# internal;
# }
# # Serve static assets with caching
# location ~* \.(?:ico|css|js|gif|jpe?g|png|woff2?|eot|ttf|svg|mp4|webm|ogv|ogg|mp3|wav|json)$ {
# expires 30d;
# add_header Cache-Control "public, no-transform";
# access_log off;
# }
# # Enable Gzip compression
# gzip on;
# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_types
# text/plain
# text/css
# application/json
# application/javascript
# text/xml
# application/xml
# application/xml+rss
# text/javascript
# image/svg+xml;
# # Logging for debugging
# error_log /var/log/nginx/error.log debug;
# access_log /var/log/nginx/access.log;
# }
server {
listen 3000;
server_name your-domain.com; # Replace with your domain or IP
# Root directory for the exported static site
root /usr/share/nginx/html;
index index.html;
# Serve static files
location / {
try_files $uri $uri.html /$uri /$uri/ /404.html;
}
# Handle 404 errors with the custom 404 page
error_page 404 /404.html;
# Serve static assets with caching
location ~* \.(?:ico|css|js|gif|jpe?g|png|woff2?|eot|ttf|svg|mp4|webm|ogv|ogg|mp3|wav|json|txt)$ {
expires 6M; # Cache static assets for 6 months
access_log off;
add_header Cache-Control "public";
}
# Enable Gzip compression for text-based assets
gzip on;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
gzip_min_length 256;
# Optional: Redirect HTTP to HTTPS (if HTTPS is set up)
# Uncomment if needed
# return 301 https://$host$request_uri;
}