Spaces:
sq66
/
v
Paused

ckst commited on
Commit
5b8eed1
·
verified ·
1 Parent(s): dd4ed6a

Update nginx.conf

Browse files
Files changed (1) hide show
  1. nginx.conf +111 -114
nginx.conf CHANGED
@@ -1,115 +1,112 @@
1
-
2
- worker_processes auto;
3
-
4
- # 设置最大打开文件数
5
- worker_rlimit_nofile 65535;
6
-
7
- events {
8
- # 每个工作进程的最大连接数
9
- worker_connections 65535;
10
-
11
- # 启用多路复用
12
- multi_accept on;
13
-
14
- # 使用高效的事件处理模型
15
- use epoll;
16
- }
17
-
18
- http {
19
-
20
-
21
- # 连接超时设置
22
- keepalive_timeout 65;
23
- keepalive_requests 100;
24
-
25
- # 压缩设置
26
- gzip on;
27
- gzip_vary on;
28
- gzip_proxied any;
29
- gzip_comp_level 6;
30
- gzip_types text/plain text/css text/xml application/json application/javascript application/rss+xml application/atom+xml image/svg+xml;
31
-
32
- # 日志配置
33
- access_log /tmp/nginx_access.log;
34
- error_log /tmp/nginx_error.log;
35
-
36
- limit_req_zone $binary_remote_addr zone=one:10m rate=10r/s;
37
- limit_conn_zone $binary_remote_addr zone=addr:10m;
38
- # MIME类型
39
- include /etc/nginx/mime.types;
40
-
41
- # 性能优化的upstream配置
42
- upstream backend {
43
- least_conn; # 最少连接负载均衡
44
- server 127.0.0.1:3000 max_fails=3 fail_timeout=30s;
45
- keepalive 32; # 保持的后端连接数
46
- }
47
-
48
- server {
49
- listen 3001 reuseport; # 启用端口重用
50
- listen [::]:3001 reuseport;
51
- server_name localhost;
52
-
53
-
54
-
55
- location /ai/ {
56
- rewrite ^/ai/(.*)$ /$1 break;
57
- limit_req zone=one burst=15 nodelay;
58
- limit_conn addr 5;
59
- proxy_pass http://backend;
60
- proxy_set_header Upgrade $http_upgrade;
61
- proxy_set_header Connection "upgrade";
62
- proxy_set_header Host $host;
63
-
64
- # 清除敏感头部
65
- proxy_set_header X-Forwarded-For "";
66
- proxy_set_header X-Real-IP "";
67
- proxy_set_header X-Direct-Url "";
68
- proxy_set_header X-Forwarded-Port "";
69
- proxy_set_header X-Ip-Token "";
70
- proxy_set_header X-Request-Id "";
71
- proxy_set_header X-Amzn-Trace-Id "";
72
- proxy_set_header X-Forwarded-Proto "";
73
-
74
- # 代理优化
75
- proxy_buffering off;
76
- proxy_cache off;
77
- proxy_connect_timeout 60s;
78
- proxy_send_timeout 60s;
79
- proxy_read_timeout 60s;
80
- error_page 503 =429 /429.html;
81
- }
82
-
83
- location / {
84
- limit_req zone=one burst=20 nodelay;
85
- limit_conn addr 10;
86
- proxy_pass http://backend;
87
- proxy_set_header Upgrade $http_upgrade;
88
- proxy_set_header Connection "upgrade";
89
- proxy_set_header Host $host;
90
-
91
- # 清除敏感头部
92
- proxy_set_header X-Forwarded-For "";
93
- proxy_set_header X-Real-IP "";
94
- proxy_set_header X-Direct-Url "";
95
- proxy_set_header X-Forwarded-Port "";
96
- proxy_set_header X-Ip-Token "";
97
- proxy_set_header X-Request-Id "";
98
- proxy_set_header X-Amzn-Trace-Id "";
99
- proxy_set_header X-Forwarded-Proto "";
100
-
101
- # 代理优化
102
- proxy_buffering off;
103
- proxy_cache off;
104
- proxy_connect_timeout 60s;
105
- proxy_send_timeout 60s;
106
- proxy_read_timeout 60s;
107
-
108
- error_page 503 =429 /429.html;
109
- }
110
- # 429 错误页面
111
- location = /429.html {
112
- return 429 'Too Many Requests';
113
- }
114
- }
115
  }
 
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
+ limit_req_zone $binary_remote_addr zone=one:10m rate=10r/s;
34
+ limit_conn_zone $binary_remote_addr zone=addr:10m;
35
+
36
+ # MIME类型
37
+ include /etc/nginx/mime.types;
38
+
39
+ # 性能优化的upstream配置
40
+ upstream backend {
41
+ least_conn; # 最少连接负载均衡
42
+ server 127.0.0.1:3000 max_fails=3 fail_timeout=30s;
43
+ keepalive 32; # 保持的后端连接数
44
+ }
45
+
46
+ server {
47
+ listen 3001 reuseport; # 启用端口重用
48
+ listen [::]:3001 reuseport;
49
+ server_name localhost;
50
+
51
+ location /ai/v1/ {
52
+ rewrite ^/ai/v1/(.*)$ /v1/$1 break;
53
+ limit_req zone=one burst=15 nodelay;
54
+ limit_conn addr 5;
55
+ proxy_pass http://backend;
56
+ proxy_set_header Upgrade $http_upgrade;
57
+ proxy_set_header Connection "upgrade";
58
+ proxy_set_header Host $host;
59
+
60
+ # 清除敏感头部
61
+ proxy_set_header X-Forwarded-For "";
62
+ proxy_set_header X-Real-IP "";
63
+ proxy_set_header X-Direct-Url "";
64
+ proxy_set_header X-Forwarded-Port "";
65
+ proxy_set_header X-Ip-Token "";
66
+ proxy_set_header X-Request-Id "";
67
+ proxy_set_header X-Amzn-Trace-Id "";
68
+ proxy_set_header X-Forwarded-Proto "";
69
+
70
+ # 代理优化
71
+ proxy_buffering off;
72
+ proxy_cache off;
73
+ proxy_connect_timeout 60s;
74
+ proxy_send_timeout 60s;
75
+ proxy_read_timeout 60s;
76
+ error_page 503 =429 /429.html;
77
+ }
78
+
79
+ location / {
80
+ limit_req zone=one burst=20 nodelay;
81
+ limit_conn addr 10;
82
+ proxy_pass http://backend;
83
+ proxy_set_header Upgrade $http_upgrade;
84
+ proxy_set_header Connection "upgrade";
85
+ proxy_set_header Host $host;
86
+
87
+ # 清除敏感头部
88
+ proxy_set_header X-Forwarded-For "";
89
+ proxy_set_header X-Real-IP "";
90
+ proxy_set_header X-Direct-Url "";
91
+ proxy_set_header X-Forwarded-Port "";
92
+ proxy_set_header X-Ip-Token "";
93
+ proxy_set_header X-Request-Id "";
94
+ proxy_set_header X-Amzn-Trace-Id "";
95
+ proxy_set_header X-Forwarded-Proto "";
96
+
97
+ # 代理优化
98
+ proxy_buffering off;
99
+ proxy_cache off;
100
+ proxy_connect_timeout 60s;
101
+ proxy_send_timeout 60s;
102
+ proxy_read_timeout 60s;
103
+
104
+ error_page 503 =429 /429.html;
105
+ }
106
+
107
+ # 429 错误页面
108
+ location = /429.html {
109
+ return 429 'Too Many Requests';
110
+ }
111
+ }
 
 
 
112
  }