41 lines
1.0 KiB
Plaintext
41 lines
1.0 KiB
Plaintext
server {
|
|
listen 80;
|
|
server_name your-domain.com;
|
|
root /path/to/your/website/dist; # 指向构建后的dist目录
|
|
index index.html;
|
|
|
|
# 优化静态资源缓存
|
|
location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ {
|
|
expires 30d;
|
|
add_header Cache-Control "public, no-transform";
|
|
}
|
|
|
|
# HTML文件不缓存,确保始终获取最新版本
|
|
location ~* \.html$ {
|
|
expires -1;
|
|
add_header Cache-Control "no-store, no-cache, must-revalidate, proxy-revalidate";
|
|
}
|
|
|
|
# 启用gzip压缩
|
|
gzip on;
|
|
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
|
|
gzip_comp_level 6;
|
|
gzip_min_length 1000;
|
|
|
|
# 默认处理
|
|
location / {
|
|
try_files $uri $uri/ /index.html;
|
|
}
|
|
|
|
# 禁止直接访问敏感文件
|
|
location ~ /\.(git|gitignore) {
|
|
deny all;
|
|
}
|
|
|
|
# 错误页面处理
|
|
error_page 404 /404.html;
|
|
location = /404.html {
|
|
root /path/to/your/website/dist;
|
|
internal;
|
|
}
|
|
} |