feat(auth): 新增站点登录(nginx auth_request + scrypt 密码 + 签名 Cookie),登录页与退出入口,API 路径保持 Key 鉴权

This commit is contained in:
sgp
2026-11-04 18:43:00 +08:00
parent ca75da8589
commit 28af756b82
6 changed files with 590 additions and 7 deletions
+31 -5
View File
@@ -1,4 +1,4 @@
# 画个标 - drawlogo.zhuig.com(纯静态站,无后端)
# 画个标 - drawlogo.zhuig.com(纯静态站 + 素材 API + 站点登录)
server {
listen 80;
listen [::]:80;
@@ -34,23 +34,49 @@ server {
# 默认入口:设计中枢首页(home.html),找不到时回落到 LOGO 工作台
index home.html index.html;
# 静态资源长期缓存(带 ?v= 版本号的 JS/CSS)
# ===== 站点登录(auth_request 子请求到 Node) =====
location = /_auth {
internal;
proxy_pass http://127.0.0.1:7891/api/v1/auth/verify;
proxy_pass_request_body off;
proxy_set_header Content-Length "";
proxy_set_header Cookie $http_cookie;
proxy_set_header X-Real-IP $remote_addr;
}
# 登录页、管理后台、品牌资源免系统登录
location = /login.html { }
location = /api-admin.html { }
location ^~ /logo/ { }
# 静态资源(需登录)
location ~* \.(js|css|woff2|ttf|svg|png|jpg|jpeg|gif|ico)$ {
auth_request /_auth;
error_page 401 = @to_login;
expires 30d;
add_header Cache-Control "public, immutable";
}
# HTML 不缓存(保证入口页及时更新)
# HTML 不缓存(需登录)
location ~* \.html$ {
auth_request /_auth;
error_page 401 = @to_login;
add_header Cache-Control "no-cache, no-store, must-revalidate";
}
# 默认首页
# 默认首页(需登录)
location / {
auth_request /_auth;
error_page 401 = @to_login;
try_files $uri $uri/ $uri/index.html =404;
}
location @to_login {
return 302 /login.html?next=$uri;
}
# 素材 API 反代(必须 ^~:否则 /api/.../*.svg 会被上面的 \.svg$ 正则截走)
# 不启用系统登录:外部项目用 API Key 鉴权
location ^~ /api/ {
proxy_pass http://127.0.0.1:7891;
proxy_set_header Host $host;
@@ -65,4 +91,4 @@ server {
access_log /var/log/nginx/drawlogo_zhuig_access.log;
error_log /var/log/nginx/drawlogo_zhuig_error.log;
}
}