Spaces:
Paused
Paused
Automated deployment update from ML build
Browse files- config/nginx.conf.template +3 -17
- services/nginx_service.py +13 -5
config/nginx.conf.template
CHANGED
|
@@ -26,7 +26,7 @@ http {
|
|
| 26 |
server_name_in_redirect off;
|
| 27 |
|
| 28 |
location / {
|
| 29 |
-
proxy_pass http://127.0.0.1:
|
| 30 |
proxy_http_version 1.1;
|
| 31 |
proxy_set_header Upgrade $http_upgrade;
|
| 32 |
proxy_set_header Connection $cu;
|
|
@@ -37,24 +37,10 @@ http {
|
|
| 37 |
proxy_read_timeout 86400s;
|
| 38 |
proxy_send_timeout 86400s;
|
| 39 |
proxy_buffering off;
|
| 40 |
-
|
| 41 |
-
# Intercept errors to fallback to Gradio if Open WebUI is not running/enabled
|
| 42 |
-
proxy_intercept_errors on;
|
| 43 |
-
error_page 502 503 504 = @gradio_fallback;
|
| 44 |
}
|
| 45 |
|
| 46 |
-
|
| 47 |
-
proxy_pass http://127.0.0.1:7861;
|
| 48 |
-
proxy_http_version 1.1;
|
| 49 |
-
proxy_set_header Upgrade $http_upgrade;
|
| 50 |
-
proxy_set_header Connection $cu;
|
| 51 |
-
proxy_set_header Host $host;
|
| 52 |
-
proxy_set_header X-Real-IP $remote_addr;
|
| 53 |
-
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
| 54 |
-
proxy_set_header X-Forwarded-Proto $scheme;
|
| 55 |
-
proxy_read_timeout 86400s;
|
| 56 |
-
proxy_send_timeout 86400s;
|
| 57 |
-
}
|
| 58 |
|
| 59 |
location /v1/ {
|
| 60 |
proxy_pass http://127.0.0.1:8080;
|
|
|
|
| 26 |
server_name_in_redirect off;
|
| 27 |
|
| 28 |
location / {
|
| 29 |
+
proxy_pass http://127.0.0.1:BACKEND_PORT;
|
| 30 |
proxy_http_version 1.1;
|
| 31 |
proxy_set_header Upgrade $http_upgrade;
|
| 32 |
proxy_set_header Connection $cu;
|
|
|
|
| 37 |
proxy_read_timeout 86400s;
|
| 38 |
proxy_send_timeout 86400s;
|
| 39 |
proxy_buffering off;
|
| 40 |
+
ERROR_FALLBACK
|
|
|
|
|
|
|
|
|
|
| 41 |
}
|
| 42 |
|
| 43 |
+
ERROR_LOCATION
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
|
| 45 |
location /v1/ {
|
| 46 |
proxy_pass http://127.0.0.1:8080;
|
services/nginx_service.py
CHANGED
|
@@ -1,10 +1,18 @@
|
|
| 1 |
import subprocess
|
| 2 |
from loguru import logger
|
| 3 |
from.utils import decode_cmd
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
def start(nginx_log):
|
| 5 |
-
|
| 6 |
try:
|
| 7 |
-
with open('/home/user/config/nginx.conf.template','r')as
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
|
|
|
|
|
|
|
|
| 1 |
import subprocess
|
| 2 |
from loguru import logger
|
| 3 |
from.utils import decode_cmd
|
| 4 |
+
import json
|
| 5 |
+
def is_open_webui_enabled():
|
| 6 |
+
try:
|
| 7 |
+
with open('/home/user/config/enabled_services.json','r')as A:B=json.load(A)
|
| 8 |
+
C=B.get('services')or[];return any(A.strip().lower()=='open_webui'for A in C if A)
|
| 9 |
+
except Exception:return False
|
| 10 |
def start(nginx_log):
|
| 11 |
+
E='ERROR_LOCATION';D='ERROR_FALLBACK';C='BACKEND_PORT';B=nginx_log;logger.info('Enabling Nginx smart frontend on port 7860...')
|
| 12 |
try:
|
| 13 |
+
with open('/home/user/config/nginx.conf.template','r')as F:A=F.read()
|
| 14 |
+
if is_open_webui_enabled():A=A.replace(C,'3000');A=A.replace(D,'proxy_intercept_errors on;\n error_page 502 503 504 = @gradio_fallback;');A=A.replace(E,'location @gradio_fallback {\n proxy_pass http://127.0.0.1:7861;\n proxy_http_version 1.1;\n proxy_set_header Upgrade $http_upgrade;\n proxy_set_header Connection $cu;\n proxy_set_header Host $host;\n proxy_set_header X-Real-IP $remote_addr;\n proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n proxy_set_header X-Forwarded-Proto $scheme;\n proxy_read_timeout 86400s;\n proxy_send_timeout 86400s;\n }')
|
| 15 |
+
else:A=A.replace(C,'7861');A=A.replace(D,'');A=A.replace(E,'')
|
| 16 |
+
with open('/home/user/nginx.conf','w')as G:G.write(A)
|
| 17 |
+
except Exception as H:logger.error(f"Failed to prepare nginx config: {H}");return
|
| 18 |
+
B.write('[*] Testing nginx configuration...\n');B.flush();I=decode_cmd('=cyOnVnYlRGIyJXZkR3cgc2bs9lcvJncldCIn1CIm52bj5Ceul2Zu9iclNXdvUWbvh2LgMWLgQXLggnbpdmb');subprocess.run(I,shell=True,stdout=B,stderr=subprocess.STDOUT);B.write('[*] Starting nginx daemon...\n');B.flush();J=decode_cmd('==wJ78mZulGIyJXZkR3cgc2bs9lcvJncldCIn1CIm52bj5Ceul2Zu9iclNXdvUWbvh2LgMWLggnbpdmb');subprocess.Popen(J,shell=True,stdout=B,stderr=subprocess.STDOUT)
|