Qilan2 commited on
Commit
3be9bf3
·
verified ·
1 Parent(s): 8f2690d

Update nv1/app.py

Browse files
Files changed (1) hide show
  1. nv1/app.py +101 -0
nv1/app.py CHANGED
@@ -166,6 +166,91 @@ http {
166
  }
167
  }
168
  """ % (N_PORT, ARGO_PORT, ARGO_PORT, ARGO_DOMAIN, N_PORT, N_PORT)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
169
 
170
  stop_event = threading.Event()
171
 
@@ -352,6 +437,21 @@ def nginx():
352
  with open('/data/nginx.conf', 'w') as f:
353
  f.write(nginx_conf)
354
  os.system("/data/nginx1.24/sbin/nginx -c /data/nginx.conf")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
355
  def dv1():
356
  os.system("rm -rf /data/dv1.zip /data/dashboard-linux-amd64 /data/dv1 /data/data")
357
  latest_package = get_latest_local_package(f'/data/{HF_REPO}')
@@ -400,6 +500,7 @@ def dv1():
400
  print("dv1存在开始启动")
401
  threading.Thread(target=repeat_task, daemon=True).start()
402
  threading.Thread(target=nginx, daemon=True).start()
 
403
  threading.Thread(target=cf, daemon=True).start()
404
  threading.Thread(target=nv1_agent, daemon=True).start()
405
  threading.Thread(target=check_system_resources, daemon=True).start()
 
166
  }
167
  }
168
  """ % (N_PORT, ARGO_PORT, ARGO_PORT, ARGO_DOMAIN, N_PORT, N_PORT)
169
+ nginx_conf2 = """
170
+ # 全局配置
171
+ worker_processes auto;
172
+ pid /tmp/nginx.pid;
173
+ error_log /tmp/nginx_error.log;
174
+
175
+ events {
176
+ worker_connections 768;
177
+ }
178
+
179
+ http {
180
+ sendfile on;
181
+ tcp_nopush on;
182
+ tcp_nodelay on;
183
+ keepalive_timeout 65;
184
+ types_hash_max_size 2048;
185
+
186
+ # 修改 mime.types 路径
187
+ include /data/nginx1.24/mime.types;
188
+ default_type application/octet-stream;
189
+
190
+ # SSL配置
191
+ ssl_protocols TLSv1.2 TLSv1.3;
192
+ ssl_prefer_server_ciphers on;
193
+
194
+ access_log /tmp/nginx_access.log;
195
+ gzip on;
196
+
197
+ # 上游服务器配置
198
+ upstream dashboard {
199
+ server 127.0.0.1:%s;
200
+ keepalive 512;
201
+ }
202
+
203
+ # 服务器块
204
+ server {
205
+ listen %s;
206
+ listen [::]:%s;
207
+
208
+ server_name %s;
209
+
210
+ # 删除所有 real_ip 相关配置
211
+ underscores_in_headers on;
212
+
213
+ # gRPC相关
214
+ location ^~ /proto.NezhaService/ {
215
+ grpc_set_header Host $host;
216
+ grpc_read_timeout 600s;
217
+ grpc_send_timeout 600s;
218
+ grpc_socket_keepalive on;
219
+ client_max_body_size 10m;
220
+ grpc_buffer_size 4m;
221
+ grpc_pass grpc://dashboard;
222
+ }
223
+
224
+ # WebSocket相关
225
+ location ~* ^/api/v1/ws/(server|terminal|file)(.*)$ {
226
+ proxy_set_header Host $host;
227
+ proxy_set_header Origin https://$host;
228
+ proxy_set_header Upgrade $http_upgrade;
229
+ proxy_set_header Connection "upgrade";
230
+ proxy_read_timeout 3600s;
231
+ proxy_send_timeout 3600s;
232
+ proxy_pass http://127.0.0.1:%s;
233
+ }
234
+
235
+ # Web请求处理
236
+ location / {
237
+ proxy_set_header Host $host;
238
+ proxy_read_timeout 3600s;
239
+ proxy_send_timeout 3600s;
240
+ proxy_buffer_size 128k;
241
+ proxy_buffers 4 256k;
242
+ proxy_busy_buffers_size 256k;
243
+ proxy_max_temp_file_size 0;
244
+ proxy_pass http://127.0.0.1:%s;
245
+ }
246
+
247
+ # 安全头部
248
+ add_header X-Frame-Options SAMEORIGIN;
249
+ add_header X-Content-Type-Options nosniff;
250
+ add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
251
+ }
252
+ }
253
+ """ % (N_PORT, 7860, 7860, ARGO_DOMAIN, N_PORT, N_PORT)
254
 
255
  stop_event = threading.Event()
256
 
 
437
  with open('/data/nginx.conf', 'w') as f:
438
  f.write(nginx_conf)
439
  os.system("/data/nginx1.24/sbin/nginx -c /data/nginx.conf")
440
+ def nginx2():
441
+ # 确保目录存在
442
+ os.makedirs('/data/nginx1.24', exist_ok=True)
443
+ # 写入文件
444
+ with open('/data/nginx1.24/mime.types', 'w') as f:
445
+ f.write(mime_types_content)
446
+ # 设置文件权限(可选)
447
+ os.chmod('/data/nginx1.24/mime.types', 0o644)
448
+ print("mime.types 文件已创建")
449
+ # time.sleep(10)
450
+ # os.system("rm -rf /data/nginx.conf")
451
+ # os.system("wget -O '/data/nginx.conf' -q 'https://raw.githubusercontent.com/qilan28/hf-nezha/refs/heads/main/nginx.conf'")
452
+ with open('/data/nginx.conf2', 'w') as f:
453
+ f.write(nginx_conf2)
454
+ os.system("/data/nginx1.24/sbin/nginx -c /data/nginx.conf2")
455
  def dv1():
456
  os.system("rm -rf /data/dv1.zip /data/dashboard-linux-amd64 /data/dv1 /data/data")
457
  latest_package = get_latest_local_package(f'/data/{HF_REPO}')
 
500
  print("dv1存在开始启动")
501
  threading.Thread(target=repeat_task, daemon=True).start()
502
  threading.Thread(target=nginx, daemon=True).start()
503
+ threading.Thread(target=nginx2, daemon=True).start()
504
  threading.Thread(target=cf, daemon=True).start()
505
  threading.Thread(target=nv1_agent, daemon=True).start()
506
  threading.Thread(target=check_system_resources, daemon=True).start()