Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,50 +1,64 @@
|
|
| 1 |
import os
|
| 2 |
import subprocess
|
|
|
|
|
|
|
| 3 |
|
| 4 |
-
#
|
|
|
|
|
|
|
|
|
|
| 5 |
html_content = """<!DOCTYPE html>
|
| 6 |
<html>
|
| 7 |
-
<head><title>
|
| 8 |
-
<style>body{font-family:sans-serif;text-align:center;padding:50px;background:#
|
| 9 |
-
.card{background:
|
| 10 |
-
h1{color:#
|
| 11 |
-
<body><div class="card"><h1>AI
|
| 12 |
-
<p>Status: <span class="ok">
|
| 13 |
|
| 14 |
with open("index.html", "w") as f:
|
| 15 |
f.write(html_content)
|
| 16 |
|
| 17 |
-
# 2. تنظیمات Nginx (
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
listen 7860;
|
| 24 |
-
|
| 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 (
|
| 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("
|
|
|
|
|
|
|
| 82 |
subprocess.Popen(["./xray", "-c", "config.json"])
|
| 83 |
|
| 84 |
-
|
| 85 |
-
|
|
|
|
|
|
|
|
|
| 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])
|