Opera8 commited on
Commit
e1479f2
·
verified ·
1 Parent(s): c64102b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -26
app.py CHANGED
@@ -1,50 +1,64 @@
1
  import os
2
  import subprocess
 
 
3
 
4
- # 1. ساخت سایت الکی (HTML)
 
 
 
5
  html_content = """<!DOCTYPE html>
6
  <html>
7
- <head><title>AI Cloud</title>
8
- <style>body{font-family:sans-serif;text-align:center;padding:50px;background:#f5f5f5;}
9
- .card{background:white;padding:30px;border-radius:10px;display:inline-block;box-shadow:0 2px 5px rgba(0,0,0,0.1);}
10
- h1{color:#333;} .ok{color:green;font-weight:bold;}</style></head>
11
- <body><div class="card"><h1>AI Model Serving</h1>
12
- <p>Status: <span class="ok">RUNNING</span></p><p>Worker ID: #X99-Alpha</p></div></body></html>"""
13
 
14
  with open("index.html", "w") as f:
15
  f.write(html_content)
16
 
17
- # 2. تنظیمات Nginx (پلیس ترافیک)
18
- # اگر مسیر /vl بود بفرست سمت فیلترشکن (پورت 3000)، در غیر این صورت سایت را نشان بده
19
- nginx_conf = """
20
- events { worker_connections 1024; }
21
- http {
22
- server {
 
 
 
 
 
 
 
 
 
 
23
  listen 7860;
24
- listen [::]:7860;
25
- root /app;
26
  index index.html;
27
 
28
- location / {
29
  try_files $uri $uri/ =404;
30
- }
31
 
32
- location /vl {
33
  proxy_redirect off;
34
  proxy_pass http://127.0.0.1:3000;
35
  proxy_http_version 1.1;
36
  proxy_set_header Upgrade $http_upgrade;
37
  proxy_set_header Connection "upgrade";
38
  proxy_set_header Host $host;
39
- }
40
- }
41
- }
42
  """
43
 
44
  with open("nginx.conf", "w") as f:
45
  f.write(nginx_conf)
46
 
47
- # 3. تنظیمات Xray (فیلترشکن روی پورت 3000 مخفی شده)
48
  xray_config = """
49
  {
50
  "log": { "loglevel": "none" },
@@ -77,9 +91,13 @@ xray_config = """
77
  with open("config.json", "w") as f:
78
  f.write(xray_config)
79
 
80
- # 4. اجرای همزمان همه
81
- print("Starting Xray...")
 
 
82
  subprocess.Popen(["./xray", "-c", "config.json"])
83
 
84
- print("Starting Nginx...")
85
- subprocess.run(["nginx", "-c", "/app/nginx.conf", "-g", "daemon off;"])
 
 
 
1
  import os
2
  import subprocess
3
+ import threading
4
+ from http.server import SimpleHTTPRequestHandler, HTTPServer
5
 
6
+ # دریافت مسیر فعلی برنامه (برای حل مشکل آدرس‌دهی)
7
+ CURRENT_DIR = os.getcwd()
8
+
9
+ # 1. ساخت سایت الکی
10
  html_content = """<!DOCTYPE html>
11
  <html>
12
+ <head><title>System Status</title>
13
+ <style>body{font-family:sans-serif;text-align:center;padding:50px;background:#f0f2f5;}
14
+ .card{background:#fff;padding:30px;border-radius:12px;display:inline-block;box-shadow:0 4px 6px rgba(0,0,0,0.1);}
15
+ h1{color:#1a73e8;} .ok{color:#34a853;font-weight:bold;}</style></head>
16
+ <body><div class="card"><h1>AI Inference Node</h1>
17
+ <p>Status: <span class="ok">OPERATIONAL</span></p><p>Region: US-East-1</p></div></body></html>"""
18
 
19
  with open("index.html", "w") as f:
20
  f.write(html_content)
21
 
22
+ # 2. تنظیمات Nginx (با آدرس‌های داینامیک و بدون نیاز به دسترسی روت)
23
+ nginx_conf = f"""
24
+ worker_processes 1;
25
+ daemon off;
26
+ pid /tmp/nginx.pid;
27
+ error_log /dev/null;
28
+ events {{ worker_connections 1024; }}
29
+ http {{
30
+ access_log off;
31
+ client_body_temp_path /tmp/client_body;
32
+ proxy_temp_path /tmp/proxy;
33
+ fastcgi_temp_path /tmp/fastcgi;
34
+ uwsgi_temp_path /tmp/uwsgi;
35
+ scgi_temp_path /tmp/scgi;
36
+
37
+ server {{
38
  listen 7860;
39
+ root {CURRENT_DIR};
 
40
  index index.html;
41
 
42
+ location / {{
43
  try_files $uri $uri/ =404;
44
+ }}
45
 
46
+ location /vl {{
47
  proxy_redirect off;
48
  proxy_pass http://127.0.0.1:3000;
49
  proxy_http_version 1.1;
50
  proxy_set_header Upgrade $http_upgrade;
51
  proxy_set_header Connection "upgrade";
52
  proxy_set_header Host $host;
53
+ }}
54
+ }}
55
+ }}
56
  """
57
 
58
  with open("nginx.conf", "w") as f:
59
  f.write(nginx_conf)
60
 
61
+ # 3. تنظیمات Xray (روی پورت 3000)
62
  xray_config = """
63
  {
64
  "log": { "loglevel": "none" },
 
91
  with open("config.json", "w") as f:
92
  f.write(xray_config)
93
 
94
+ # 4. اجرای سرویس‌ها
95
+ print(f"Working Directory: {CURRENT_DIR}")
96
+
97
+ # اجرای Xray
98
  subprocess.Popen(["./xray", "-c", "config.json"])
99
 
100
+ # اجرای Nginx با آدرس فایل کانفیگ دقیق
101
+ nginx_config_path = os.path.join(CURRENT_DIR, "nginx.conf")
102
+ print(f"Starting Nginx using config: {nginx_config_path}")
103
+ subprocess.run(["nginx", "-c", nginx_config_path])