-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathnginx.conf
More file actions
112 lines (93 loc) · 3.75 KB
/
Copy pathnginx.conf
File metadata and controls
112 lines (93 loc) · 3.75 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
limit_req_status 429;
limit_req_zone $binary_remote_addr zone=api_limit:10m rate=10r/s;
server {
listen 80;
server_name api.librechat.ai;
# Necessary forwarding of Real IP's
# User → Cloudflare → DO Load Balancer → Nginx → Express
real_ip_header CF-Connecting-IP;
# DO Load Balancer range
set_real_ip_from 10.0.0.0/8;
# Cloudflare IPs
set_real_ip_from 173.245.48.0/20;
set_real_ip_from 103.21.244.0/22;
set_real_ip_from 103.22.200.0/22;
set_real_ip_from 103.31.4.0/22;
set_real_ip_from 141.101.64.0/18;
set_real_ip_from 108.162.192.0/18;
set_real_ip_from 190.93.240.0/20;
set_real_ip_from 188.114.96.0/20;
set_real_ip_from 197.234.240.0/22;
set_real_ip_from 198.41.128.0/17;
set_real_ip_from 162.158.0.0/15;
set_real_ip_from 104.16.0.0/13;
set_real_ip_from 104.24.0.0/14;
set_real_ip_from 172.64.0.0/13;
set_real_ip_from 131.0.72.0/22;
# Set default client body size to something small (e.g., 1M)
client_max_body_size 1M;
# Logging
access_log /var/log/nginx/api_access.log;
error_log /var/log/nginx/api_error.log warn;
location /health {
access_log off;
add_header Content-Type text/plain;
return 200 'healthy';
}
# Specific location for uploads with 25M limit
location /v1/upload {
limit_req zone=api_limit burst=20 nodelay;
# Check for X-API-Key header
if ($http_x_api_key = "") {
add_header Content-Type application/json;
return 403 '{"error": "API Key required"}';
}
client_max_body_size 25M;
proxy_pass http://172.17.0.1:3112;
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 $http_cf_connecting_ip;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
# timeout
proxy_connect_timeout 120s;
proxy_send_timeout 120s;
proxy_read_timeout 120s;
# Security headers
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-XSS-Protection "1; mode=block" always;
add_header X-Content-Type-Options "nosniff" always;
add_header Referrer-Policy "no-referrer-when-downgrade" always;
add_header Content-Security-Policy "default-src 'self' http: https: data: blob: 'unsafe-inline'" always;
}
# General location for all other endpoints
location / {
limit_req zone=api_limit burst=20 nodelay;
# Check for X-API-Key header
if ($http_x_api_key = "") {
add_header Content-Type application/json;
return 403 '{"error": "API Key required"}';
}
client_max_body_size 1M; # Stricter limit for non-upload endpoints
proxy_pass http://172.17.0.1:3112;
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 $http_cf_connecting_ip;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
# timeout
proxy_connect_timeout 120s;
proxy_send_timeout 120s;
proxy_read_timeout 120s;
# Security headers
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-XSS-Protection "1; mode=block" always;
add_header X-Content-Type-Options "nosniff" always;
add_header Referrer-Policy "no-referrer-when-downgrade" always;
add_header Content-Security-Policy "default-src 'self' http: https: data: blob: 'unsafe-inline'" always;
}
}