Files
blog/write-server/nginx/conf.d/write-server.conf
T

101 lines
2.6 KiB
Plaintext
Raw Normal View History

2026-06-21 20:42:44 +08:00
# Write Server Nginx 站点配置
2026-06-21 23:28:31 +08:00
# HTTP -> HTTPS 重定向
2026-06-21 20:42:44 +08:00
server {
listen 80;
2026-06-21 23:28:31 +08:00
server_name post.usj.cc;
# Let's Encrypt 验证
location /.well-known/acme-challenge/ {
root /var/www/certbot;
}
# 其他请求重定向到 HTTPS
location / {
return 301 https://$host$request_uri;
}
}
# HTTPS 主站
server {
listen 443 ssl http2;
server_name post.usj.cc;
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;
2026-06-21 20:42:44 +08:00
access_log /var/log/nginx/write-server-access.log;
error_log /var/log/nginx/write-server-error.log;
2026-06-21 23:28:31 +08:00
# 静态文件(登录页、Service Worker、htpasswd 验证)
location /sw.js {
alias /etc/nginx/sw.js;
add_header Content-Type application/javascript;
add_header Cache-Control "no-cache, no-store";
2026-06-21 22:22:38 +08:00
}
2026-06-21 20:42:44 +08:00
2026-06-21 23:28:31 +08:00
location /login.html {
alias /etc/nginx/login.html;
add_header Cache-Control "no-cache, no-store";
}
location /auth/check {
auth_basic "Write Server";
auth_basic_user_file /etc/nginx/.htpasswd;
return 200 'ok';
add_header Content-Type text/plain;
}
2026-06-22 00:52:51 +08:00
# Hugo 预览代理(不需要认证)
location /preview/ {
auth_request off;
rewrite ^/preview/(.*)$ /$1 break;
proxy_pass http://write-server:1313;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
2026-06-21 23:28:31 +08:00
# 所有其他请求通过 auth_request 验证
2026-06-21 20:42:44 +08:00
location / {
2026-06-21 23:28:31 +08:00
auth_request /auth/internal;
2026-06-21 20:42:44 +08:00
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;
2026-06-21 22:22:38 +08:00
proxy_read_timeout 120s;
client_max_body_size 50m;
2026-06-21 23:28:31 +08:00
error_page 401 = @login;
}
location = /auth/internal {
internal;
proxy_pass http://write-server:8016/api/stats;
proxy_set_header Authorization $http_authorization;
proxy_pass_request_body off;
proxy_set_header Content-Length "";
}
location @login {
internal;
add_header WWW-Authenticate "";
return 302 /login.html;
2026-06-21 20:42:44 +08:00
}
location ~ /\. {
deny all;
access_log off;
log_not_found off;
}
}