Files
blog/write-server/nginx/conf.d/write-server.conf
T
2026-06-21 20:42:44 +08:00

88 lines
2.5 KiB
Plaintext

# Write Server Nginx 站点配置
# 反向代理配置
# HTTP 重定向到 HTTPS(可选)
# server {
# listen 80;
# server_name write.your-domain.com;
# return 301 https://$server_name$request_uri;
# }
# 主站点配置
server {
listen 80;
# listen 443 ssl http2; # 启用 HTTPS 时取消注释
server_name write.your-domain.com; # 替换为你的域名
# SSL 配置(启用 HTTPS 时取消注释)
# ssl_certificate /etc/nginx/ssl/fullchain.pem;
# ssl_certificate_key /etc/nginx/ssl/privkey.pem;
# ssl_protocols TLSv1.2 TLSv1.3;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# 日志
access_log /var/log/nginx/write-server-access.log;
error_log /var/log/nginx/write-server-error.log;
# 安全限制
# 限制访问 IP(可选)
# allow 192.168.1.0/24;
# allow 10.0.0.0/8;
# deny all;
# 代理到 Write Server
location / {
proxy_pass http://write-server:8016;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_cache_bypass $http_upgrade;
# 超时设置
proxy_connect_timeout 60s;
proxy_send_timeout 60s;
proxy_read_timeout 60s;
}
# 静态资源缓存
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
proxy_pass http://write-server:8016;
expires 1y;
add_header Cache-Control "public, immutable";
}
# API 路径不缓存
location /api/ {
proxy_pass http://write-server:8016;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_cache_bypass $http_upgrade;
# 禁止缓存 API 响应
add_header Cache-Control "no-cache, no-store, must-revalidate";
}
# 禁止访问隐藏文件
location ~ /\. {
deny all;
access_log off;
log_not_found off;
}
# 健康检查端点
location /health {
proxy_pass http://write-server:8016/api/stats;
access_log off;
}
}