dragg2 commited on
Commit
beca17d
·
verified ·
1 Parent(s): e13cd97

Update nginx.conf

Browse files
Files changed (1) hide show
  1. nginx.conf +113 -31
nginx.conf CHANGED
@@ -1,32 +1,114 @@
1
- user nginx;
2
-
3
- events {
4
- worker_connections 1024;
5
- }
6
-
7
- http {
8
- # 禁用 admin 接口和日志输出
9
- server {
10
- listen 3001;
11
-
12
- location /ai/v1/ {
13
- rewrite ^/ai/v1/(.*)$ /v1/$1 break;
14
- proxy_pass http://127.0.0.1:3000;
15
- proxy_set_header Host $host;
16
- proxy_set_header X-Real-IP $remote_addr;
17
- proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
18
- proxy_set_header X-Forwarded-Proto $scheme;
19
- }
20
-
21
- location / {
22
- proxy_pass http://127.0.0.1:3000;
23
- proxy_set_header Host $host;
24
- proxy_set_header X-Real-IP $remote_addr;
25
- proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
26
- proxy_set_header X-Forwarded-Proto $scheme;
27
- }
28
- }
29
-
30
- # 禁用错误日志输出
31
- error_log /dev/null crit;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
  }
 
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
+
20
+ # 连接超时设置
21
+ keepalive_timeout 120;
22
+ keepalive_requests 100;
23
+
24
+ # 压缩设置
25
+ gzip on;
26
+ gzip_vary on;
27
+ gzip_proxied any;
28
+ gzip_comp_level 6;
29
+ gzip_types text/plain text/css text/xml application/json application/javascript application/rss+xml application/atom+xml image/svg+xml;
30
+
31
+ # 日志配置
32
+ access_log /tmp/nginx_access.log;
33
+ error_log /tmp/nginx_error.log;
34
+
35
+ limit_req_zone $binary_remote_addr zone=one:10m rate=10r/s;
36
+ limit_conn_zone $binary_remote_addr zone=addr:10m;
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 7860 reuseport; # 启用端口重用
49
+ listen [::]:7860 reuseport;
50
+ server_name localhost;
51
+
52
+
53
+
54
+ location /hf/ {
55
+ rewrite ^/hf/(.*)$ /$1 break;
56
+ limit_req zone=one burst=15 nodelay;
57
+ limit_conn addr 5;
58
+ proxy_pass http://backend;
59
+ proxy_set_header Upgrade $http_upgrade;
60
+ proxy_set_header Connection "upgrade";
61
+ proxy_set_header Host $host;
62
+
63
+ # 清除敏感头部
64
+ proxy_set_header X-Forwarded-For "";
65
+ proxy_set_header X-Real-IP "";
66
+ proxy_set_header X-Direct-Url "";
67
+ proxy_set_header X-Forwarded-Port "";
68
+ proxy_set_header X-Ip-Token "";
69
+ proxy_set_header X-Request-Id "";
70
+ proxy_set_header X-Amzn-Trace-Id "";
71
+ proxy_set_header X-Forwarded-Proto "";
72
+
73
+ # 代理优化
74
+ proxy_buffering off;
75
+ proxy_cache off;
76
+ proxy_connect_timeout 120s;
77
+ proxy_send_timeout 120s;
78
+ proxy_read_timeout 120s;
79
+ error_page 503 =429 /429.html;
80
+ }
81
+
82
+ location / {
83
+ limit_req zone=one burst=20 nodelay;
84
+ limit_conn addr 10;
85
+ proxy_pass http://backend;
86
+ proxy_set_header Upgrade $http_upgrade;
87
+ proxy_set_header Connection "upgrade";
88
+ proxy_set_header Host $host;
89
+
90
+ # 清除敏感头部
91
+ proxy_set_header X-Forwarded-For "";
92
+ proxy_set_header X-Real-IP "";
93
+ proxy_set_header X-Direct-Url "";
94
+ proxy_set_header X-Forwarded-Port "";
95
+ proxy_set_header X-Ip-Token "";
96
+ proxy_set_header X-Request-Id "";
97
+ proxy_set_header X-Amzn-Trace-Id "";
98
+ proxy_set_header X-Forwarded-Proto "";
99
+
100
+ # 代理优化
101
+ proxy_buffering off;
102
+ proxy_cache off;
103
+ proxy_connect_timeout 60s;
104
+ proxy_send_timeout 60s;
105
+ proxy_read_timeout 60s;
106
+
107
+ error_page 503 =429 /429.html;
108
+ }
109
+ # 429 错误页面
110
+ location = /429.html {
111
+ return 429 'Too Many Requests';
112
+ }
113
+ }
114
  }