- config: 反向代理、缓存、负载均衡、安全、SSL 等配置模板 - lua: API 网关、认证、动态路由、限流、WebSocket 等脚本示例 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
74 lines
1.9 KiB
Plaintext
74 lines
1.9 KiB
Plaintext
# ============================================================
|
|
# Nginx 静态文件服务器配置示例
|
|
# ============================================================
|
|
#
|
|
# 功能说明:
|
|
# - 静态文件服务,支持索引文件和目录浏览
|
|
# - try_files 支持 SPA 部署和 fallback
|
|
# - sendfile 零拷贝传输优化
|
|
#
|
|
# Lolly 对应配置:
|
|
# server:
|
|
# static:
|
|
# - path: "/"
|
|
# root: "/var/www/html"
|
|
# index: ["index.html", "index.htm"]
|
|
# try_files: ["$uri", "$uri/", "/index.html"] # SPA 部署
|
|
# try_files_pass: false
|
|
# ============================================================
|
|
|
|
server {
|
|
listen 80;
|
|
server_name static.example.com;
|
|
|
|
# 静态文件根目录
|
|
root /var/www/html;
|
|
|
|
# 索引文件
|
|
index index.html index.htm index.php;
|
|
|
|
# 零拷贝传输优化
|
|
sendfile on;
|
|
sendfile_max_chunk 1m;
|
|
tcp_nopush on;
|
|
tcp_nodelay on;
|
|
|
|
# 文件访问日志
|
|
access_log /var/log/nginx/static.access.log combined;
|
|
|
|
# 主 location
|
|
location / {
|
|
# try_files: 按顺序尝试文件,最后 fallback 到 index.html
|
|
# Lolly 对应: try_files: ["$uri", "$uri/", "/index.html"]
|
|
try_files $uri $uri/ /index.html;
|
|
|
|
# 目录浏览(可选)
|
|
# autoindex on;
|
|
# autoindex_exact_size off;
|
|
# autoindex_localtime on;
|
|
}
|
|
|
|
# 静态资源缓存
|
|
location ~* \.(jpg|jpeg|png|gif|ico|css|js|svg|woff|woff2|ttf|eot)$ {
|
|
expires 30d;
|
|
add_header Cache-Control "public, immutable";
|
|
access_log off;
|
|
}
|
|
|
|
# 禁止访问隐藏文件
|
|
location ~ /\. {
|
|
deny all;
|
|
access_log off;
|
|
log_not_found off;
|
|
}
|
|
|
|
# 自定义错误页面
|
|
# Lolly 对应: security.error_page.pages: {404: "/errors/404.html"}
|
|
error_page 404 /errors/404.html;
|
|
error_page 500 502 503 504 /errors/50x.html;
|
|
|
|
location /errors/ {
|
|
internal;
|
|
root /var/www/errors;
|
|
}
|
|
} |