Spaces:
hequ
/
v
Paused

hequ commited on
Commit
4c194d8
·
verified ·
1 Parent(s): 3413864

Update nginx.conf

Browse files
Files changed (1) hide show
  1. nginx.conf +17 -41
nginx.conf CHANGED
@@ -1,69 +1,52 @@
1
  worker_processes auto;
2
-
3
- # 设置最大打开文件数
4
  worker_rlimit_nofile 65535;
5
 
6
  events {
7
- # 每个工作进程的最大连接数
8
  worker_connections 65535;
9
-
10
- # 启用多路复用
11
  multi_accept on;
12
-
13
- # 使用高效的事件处理模型
14
  use epoll;
15
  }
16
 
17
  http {
18
- # 连接超时设置
19
  keepalive_timeout 65;
20
  keepalive_requests 100;
21
 
22
- # 压缩设置
23
  gzip on;
24
  gzip_vary on;
25
  gzip_proxied any;
26
  gzip_comp_level 6;
27
  gzip_types text/plain text/css text/xml application/json application/javascript application/rss+xml application/atom+xml image/svg+xml;
28
 
29
- # 日志配置
30
  access_log /tmp/nginx_access.log;
31
  error_log /tmp/nginx_error.log;
32
 
33
- # 请求速率和连接数限制区域定义
34
  limit_req_zone $binary_remote_addr zone=one:10m rate=10r/s;
35
  limit_conn_zone $binary_remote_addr zone=addr:10m;
36
 
37
- # MIME类型
38
  include /etc/nginx/mime.types;
39
 
40
- # 性能优化的upstream配置
41
  upstream backend {
42
- least_conn; # 最少连接负载均衡
43
  server 127.0.0.1:3000 max_fails=3 fail_timeout=30s;
44
- keepalive 32; # 保持的后端连接数
45
  }
46
 
47
  server {
48
- listen 3001 reuseport; # 启用端口重用
49
  listen [::]:3001 reuseport;
50
  server_name localhost;
51
 
52
- # <<<--- 添加在这里:设置允许的最大请求体大小 --->>>
53
- # 默认是 1m,如果请求体超过此大小会报 413 Request Entity Too Large
54
- # 根据你的需要调整这个值,例如 100m, 500m, 1g 等
55
- client_max_body_size 100m;
56
 
57
  location /ai/v1/ {
58
  rewrite ^/ai/v1/(.*)$ /v1/$1 break;
59
- limit_req zone=one burst=15 nodelay; # 请求速率限制
60
- limit_conn addr 5; # 单IP并发连接数限制
61
  proxy_pass http://backend;
62
  proxy_set_header Upgrade $http_upgrade;
63
- proxy_set_header Connection "upgrade"; # 支持 WebSocket
64
  proxy_set_header Host $host;
65
 
66
- # 清除敏感头部,增强安全性
67
  proxy_set_header X-Forwarded-For "";
68
  proxy_set_header X-Real-IP "";
69
  proxy_set_header X-Direct-Url "";
@@ -73,26 +56,23 @@ http {
73
  proxy_set_header X-Amzn-Trace-Id "";
74
  proxy_set_header X-Forwarded-Proto "";
75
 
76
- # 代理优化 (关闭缓冲可能增加后端压力,但适合流式或长连接)
77
  proxy_buffering off;
78
  proxy_cache off;
79
- proxy_connect_timeout 60s; # 连接后端超时
80
- proxy_send_timeout 3000s; # 发送请求到后端超时 (50分钟,非常长)
81
- proxy_read_timeout 3000s; # 从后端读取响应超时 (50分钟,非常长)
82
 
83
- # 将限流等情况可能导致的503错误映射为429
84
  error_page 503 =429 /429.html;
85
  }
86
 
87
  location / {
88
- limit_req zone=one burst=20 nodelay; # 请求速率限制
89
- limit_conn addr 10; # 单IP并发连接数限制
90
  proxy_pass http://backend;
91
  proxy_set_header Upgrade $http_upgrade;
92
- proxy_set_header Connection "upgrade"; # 支持 WebSocket
93
  proxy_set_header Host $host;
94
 
95
- # 清除敏感头部
96
  proxy_set_header X-Forwarded-For "";
97
  proxy_set_header X-Real-IP "";
98
  proxy_set_header X-Direct-Url "";
@@ -102,22 +82,18 @@ http {
102
  proxy_set_header X-Amzn-Trace-Id "";
103
  proxy_set_header X-Forwarded-Proto "";
104
 
105
- # 代理优化
106
  proxy_buffering off;
107
  proxy_cache off;
108
  proxy_connect_timeout 60s;
109
- proxy_send_timeout 3000s; # (50分钟,非常长)
110
- proxy_read_timeout 3000s; # (50分钟,非常长)
111
 
112
- # 将限流等情况可能导致的503错误映射为429
113
  error_page 503 =429 /429.html;
114
  }
115
 
116
- # 自定义 429 错误响应
117
  location = /429.html {
118
- internal; # 只允许内部访问
119
- return 429 '{"error": "Too Many Requests"}'; # 返回 JSON 格式错误可能更适合 API
120
- # 或者保持原来的文本格式: return 429 'Too Many Requests';
121
  }
122
  }
123
  }
 
1
  worker_processes auto;
 
 
2
  worker_rlimit_nofile 65535;
3
 
4
  events {
 
5
  worker_connections 65535;
 
 
6
  multi_accept on;
 
 
7
  use epoll;
8
  }
9
 
10
  http {
 
11
  keepalive_timeout 65;
12
  keepalive_requests 100;
13
 
 
14
  gzip on;
15
  gzip_vary on;
16
  gzip_proxied any;
17
  gzip_comp_level 6;
18
  gzip_types text/plain text/css text/xml application/json application/javascript application/rss+xml application/atom+xml image/svg+xml;
19
 
 
20
  access_log /tmp/nginx_access.log;
21
  error_log /tmp/nginx_error.log;
22
 
 
23
  limit_req_zone $binary_remote_addr zone=one:10m rate=10r/s;
24
  limit_conn_zone $binary_remote_addr zone=addr:10m;
25
 
 
26
  include /etc/nginx/mime.types;
27
 
 
28
  upstream backend {
29
+ least_conn;
30
  server 127.0.0.1:3000 max_fails=3 fail_timeout=30s;
31
+ keepalive 32;
32
  }
33
 
34
  server {
35
+ listen 3001 reuseport;
36
  listen [::]:3001 reuseport;
37
  server_name localhost;
38
 
39
+ client_max_body_size 1000m;
 
 
 
40
 
41
  location /ai/v1/ {
42
  rewrite ^/ai/v1/(.*)$ /v1/$1 break;
43
+ limit_req zone=one burst=15 nodelay;
44
+ limit_conn addr 5;
45
  proxy_pass http://backend;
46
  proxy_set_header Upgrade $http_upgrade;
47
+ proxy_set_header Connection "upgrade";
48
  proxy_set_header Host $host;
49
 
 
50
  proxy_set_header X-Forwarded-For "";
51
  proxy_set_header X-Real-IP "";
52
  proxy_set_header X-Direct-Url "";
 
56
  proxy_set_header X-Amzn-Trace-Id "";
57
  proxy_set_header X-Forwarded-Proto "";
58
 
 
59
  proxy_buffering off;
60
  proxy_cache off;
61
+ proxy_connect_timeout 60s;
62
+ proxy_send_timeout 3000s;
63
+ proxy_read_timeout 3000s;
64
 
 
65
  error_page 503 =429 /429.html;
66
  }
67
 
68
  location / {
69
+ limit_req zone=one burst=20 nodelay;
70
+ limit_conn addr 10;
71
  proxy_pass http://backend;
72
  proxy_set_header Upgrade $http_upgrade;
73
+ proxy_set_header Connection "upgrade";
74
  proxy_set_header Host $host;
75
 
 
76
  proxy_set_header X-Forwarded-For "";
77
  proxy_set_header X-Real-IP "";
78
  proxy_set_header X-Direct-Url "";
 
82
  proxy_set_header X-Amzn-Trace-Id "";
83
  proxy_set_header X-Forwarded-Proto "";
84
 
 
85
  proxy_buffering off;
86
  proxy_cache off;
87
  proxy_connect_timeout 60s;
88
+ proxy_send_timeout 3000s;
89
+ proxy_read_timeout 3000s;
90
 
 
91
  error_page 503 =429 /429.html;
92
  }
93
 
 
94
  location = /429.html {
95
+ internal;
96
+ return 429 '{"error": "Too Many Requests"}';
 
97
  }
98
  }
99
  }