48 lines
1.2 KiB
Text
48 lines
1.2 KiB
Text
|
|
# Yukun's Blog · nginx 共享服务配置片段
|
|||
|
|
# 由 deploy/deploy.sh setup-nginx 上传到 /etc/nginx/snippets/yukun.conf
|
|||
|
|
# 80 与 443 段都 include 此文件,避免重复
|
|||
|
|
|
|||
|
|
root /var/www/yukun;
|
|||
|
|
index index.html;
|
|||
|
|
|
|||
|
|
# gzip 压缩
|
|||
|
|
gzip on;
|
|||
|
|
gzip_vary on;
|
|||
|
|
gzip_min_length 1024;
|
|||
|
|
gzip_comp_level 6;
|
|||
|
|
gzip_types
|
|||
|
|
text/plain
|
|||
|
|
text/css
|
|||
|
|
text/xml
|
|||
|
|
text/javascript
|
|||
|
|
application/javascript
|
|||
|
|
application/x-javascript
|
|||
|
|
application/json
|
|||
|
|
application/xml
|
|||
|
|
application/xml+rss
|
|||
|
|
image/svg+xml;
|
|||
|
|
|
|||
|
|
# 静态资源长缓存(Astro 构建产物带 hash,可放心强缓存)
|
|||
|
|
location ~* \.(?:css|js|woff2?|ttf|otf|svg|png|jpg|jpeg|gif|webp|ico|avif)$ {
|
|||
|
|
expires 30d;
|
|||
|
|
add_header Cache-Control "public, immutable";
|
|||
|
|
access_log off;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
# sitemap 不缓存
|
|||
|
|
location = /sitemap-index.xml { add_header Cache-Control "no-cache"; }
|
|||
|
|
location ~ ^/sitemap.* { add_header Cache-Control "no-cache"; }
|
|||
|
|
|
|||
|
|
# Astro 目录式 URL,确保 index.html 能解析
|
|||
|
|
location / {
|
|||
|
|
try_files $uri $uri/ $uri.html =404;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
# 自定义 404
|
|||
|
|
error_page 404 /404.html;
|
|||
|
|
|
|||
|
|
# 安全头
|
|||
|
|
add_header X-Content-Type-Options "nosniff" always;
|
|||
|
|
add_header X-Frame-Options "SAMEORIGIN" always;
|
|||
|
|
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
|