70 lines
2.1 KiB
Plaintext
70 lines
2.1 KiB
Plaintext
server {
|
|
listen 80;
|
|
server_name rag-server.svc.plus api.svc.plus;
|
|
return 301 https://$host$request_uri;
|
|
}
|
|
|
|
server {
|
|
listen 443 ssl;
|
|
server_name rag-server.svc.plus api.svc.plus;
|
|
|
|
ssl_certificate /etc/letsencrypt/live/svc.plus/fullchain.pem;
|
|
ssl_certificate_key /etc/letsencrypt/live/svc.plus/privkey.pem;
|
|
ssl_protocols TLSv1.2 TLSv1.3;
|
|
ssl_ciphers HIGH:!aNULL:!MD5;
|
|
|
|
location ^~ /api/ {
|
|
proxy_pass http://rag-server:8090;
|
|
proxy_http_version 1.1;
|
|
|
|
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;
|
|
|
|
add_header Access-Control-Allow-Origin $cors_origin always;
|
|
add_header Access-Control-Allow-Methods "GET, POST, PUT, DELETE, OPTIONS" always;
|
|
add_header Access-Control-Allow-Headers "Authorization, Content-Type, Cookie" always;
|
|
add_header Access-Control-Allow-Credentials "true" always;
|
|
|
|
if ($request_method = OPTIONS) {
|
|
return 204;
|
|
}
|
|
|
|
add_header Cache-Control "no-store";
|
|
}
|
|
|
|
location = /api/askai {
|
|
access_by_lua_block {
|
|
local redis = require "resty.redis"
|
|
local r = redis:new()
|
|
r:set_timeout(200)
|
|
local ok, err = r:connect("redis", 6379)
|
|
if not ok then
|
|
ngx.log(ngx.ERR, "Redis connect error: ", err)
|
|
return ngx.exit(500)
|
|
end
|
|
|
|
local user = ngx.var.arg_user or ngx.var.remote_addr
|
|
local today = os.date("%Y%m%d")
|
|
local key = "limit:user:" .. user .. ":" .. today
|
|
|
|
local count, err = r:incr(key)
|
|
if count == 1 then r:expire(key, 86400) end
|
|
if count > 200 then
|
|
ngx.status = 429
|
|
ngx.header["Content-Type"] = "text/plain; charset=utf-8"
|
|
ngx.say("Too Many Requests: daily limit reached")
|
|
return ngx.exit(429)
|
|
end
|
|
}
|
|
|
|
proxy_pass http://rag-server:8090;
|
|
proxy_http_version 1.1;
|
|
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;
|
|
}
|
|
}
|