tang-x commited on
Commit
4ba1e60
·
verified ·
1 Parent(s): 8818e29

Update nginx.conf

Browse files
Files changed (1) hide show
  1. nginx.conf +114 -31
nginx.conf CHANGED
@@ -1,32 +1,115 @@
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
+
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 120;
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 7860 reuseport; # 启用端口重用
50
+ listen [::]:7860 reuseport;
51
+ server_name localhost;
52
+
53
+
54
+
55
+ location /hf/ {
56
+ rewrite ^/hf/(.*)$ /$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 120s;
78
+ proxy_send_timeout 120s;
79
+ proxy_read_timeout 120s;
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
  }