-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathnginx.conf
More file actions
49 lines (39 loc) · 1.31 KB
/
nginx.conf
File metadata and controls
49 lines (39 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
limit_req_zone $binary_remote_addr zone=api:10m rate=10r/s;
server {
listen 80;
server_name _;
# Security headers on every response
add_header X-Content-Type-Options "nosniff" always;
add_header X-Frame-Options "DENY" always;
# Health check — no auth required
location = /health {
default_type application/json;
return 200 '{"status":"ok"}';
}
# Chat API — rate-limited, API-key-protected, POST-only
location = /api/chat {
limit_req zone=api burst=20 nodelay;
limit_req_status 429;
# Validate API key
if ($http_x_api_key != "${VALID_API_KEY}") {
return 401 '{"error":"invalid or missing API key"}';
}
# Only allow POST
if ($request_method != POST) {
return 405 '{"error":"method not allowed"}';
}
proxy_pass http://middleware:8000/chat;
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_connect_timeout 5s;
proxy_read_timeout 10s;
proxy_send_timeout 5s;
default_type application/json;
}
# Everything else — 404
location / {
default_type application/json;
return 404 '{"error":"not found"}';
}
}