Spaces:
Sleeping
Sleeping
Update nginx.conf
Browse files- nginx.conf +31 -45
nginx.conf
CHANGED
|
@@ -1,86 +1,72 @@
|
|
| 1 |
server {
|
| 2 |
-
# Lắng nghe cổng 4444 (cổng mà bạn EXPOSE trong Dockerfile)
|
| 3 |
listen 4444 default_server;
|
| 4 |
listen [::]:4444 default_server;
|
| 5 |
|
| 6 |
server_name _;
|
| 7 |
|
| 8 |
# ------------------------------------------------
|
| 9 |
-
# 1.
|
| 10 |
# ------------------------------------------------
|
| 11 |
-
|
| 12 |
-
# Nếu người dùng truy cập /gradio (KHÔNG có / ở cuối),
|
| 13 |
-
# Nginx sẽ trả về HTTP 302 (Moved Temporarily) để chuyển hướng họ đến /gradio/.
|
| 14 |
-
location = /gradio {
|
| 15 |
-
return 302 /gradio/;
|
| 16 |
-
}
|
| 17 |
|
| 18 |
-
#
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
# ------------------------------------------------
|
| 26 |
-
# 2. Định tuyến cho GRADIO (Sau khi đã có dấu /)
|
| 27 |
-
# ------------------------------------------------
|
| 28 |
-
|
| 29 |
-
# Khớp với /gradio/ và mọi thứ theo sau (/gradio/app, /gradio/static, v.v.)
|
| 30 |
-
location /gradio/ {
|
| 31 |
# Proxy_pass đến cổng 7860 (Gradio/FastAPI)
|
| 32 |
-
# Dấu
|
| 33 |
-
|
| 34 |
-
proxy_pass http://localhost:7860/;
|
| 35 |
|
| 36 |
-
# Cấu hình
|
| 37 |
proxy_http_version 1.1;
|
| 38 |
proxy_set_header Upgrade $http_upgrade;
|
| 39 |
proxy_set_header Connection 'upgrade';
|
| 40 |
|
| 41 |
-
#
|
| 42 |
proxy_set_header Host $host;
|
| 43 |
proxy_set_header X-Real-IP $remote_addr;
|
| 44 |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
| 45 |
proxy_cache_bypass $http_upgrade;
|
| 46 |
|
| 47 |
-
# Tăng timeout cho các tác vụ ML dài
|
| 48 |
proxy_read_timeout 86400;
|
| 49 |
proxy_redirect off;
|
| 50 |
}
|
| 51 |
|
| 52 |
|
| 53 |
# ------------------------------------------------
|
| 54 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
# ------------------------------------------------
|
| 56 |
|
| 57 |
-
# Khớp với /streamlit/ và mọi thứ theo sau
|
| 58 |
location /streamlit/ {
|
| 59 |
-
#
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
|
|
|
|
|
|
| 64 |
proxy_http_version 1.1;
|
| 65 |
proxy_set_header Upgrade $http_upgrade;
|
| 66 |
proxy_set_header Connection 'upgrade';
|
|
|
|
|
|
|
| 67 |
proxy_set_header Host $host;
|
| 68 |
proxy_set_header X-Real-IP $remote_addr;
|
| 69 |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
| 70 |
proxy_cache_bypass $http_upgrade;
|
| 71 |
|
| 72 |
-
# Tăng timeout
|
| 73 |
proxy_read_timeout 86400;
|
| 74 |
proxy_redirect off;
|
| 75 |
}
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
# ------------------------------------------------
|
| 79 |
-
# 4. Trang chủ mặc định
|
| 80 |
-
# ------------------------------------------------
|
| 81 |
-
|
| 82 |
-
# Nếu người dùng chỉ truy cập https://...hf.space/
|
| 83 |
-
location / {
|
| 84 |
-
return 302 /gradio/; # Chuyển hướng đến Gradio làm trang chủ mặc định
|
| 85 |
-
}
|
| 86 |
}
|
|
|
|
| 1 |
server {
|
|
|
|
| 2 |
listen 4444 default_server;
|
| 3 |
listen [::]:4444 default_server;
|
| 4 |
|
| 5 |
server_name _;
|
| 6 |
|
| 7 |
# ------------------------------------------------
|
| 8 |
+
# 1. Định tuyến cho GRADIO (URL Gốc / Trang chủ)
|
| 9 |
# ------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
+
# Mọi thứ (trừ /streamlit) sẽ được chuyển đến Gradio.
|
| 12 |
+
location / {
|
| 13 |
+
# HEADER quan trọng cho Gradio/FastAPI để nhận biết đường dẫn gốc
|
| 14 |
+
# Trong trường hợp này, X-Forwarded-Prefix không cần thiết, nhưng không hại.
|
| 15 |
+
proxy_set_header X-Forwarded-Prefix /;
|
| 16 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
# Proxy_pass đến cổng 7860 (Gradio/FastAPI)
|
| 18 |
+
# Dấu / ở cuối proxy_pass rất quan trọng
|
| 19 |
+
proxy_pass http://localhost:7860/;
|
|
|
|
| 20 |
|
| 21 |
+
# Cấu hình WebSockets
|
| 22 |
proxy_http_version 1.1;
|
| 23 |
proxy_set_header Upgrade $http_upgrade;
|
| 24 |
proxy_set_header Connection 'upgrade';
|
| 25 |
|
| 26 |
+
# Headers chuẩn
|
| 27 |
proxy_set_header Host $host;
|
| 28 |
proxy_set_header X-Real-IP $remote_addr;
|
| 29 |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
| 30 |
proxy_cache_bypass $http_upgrade;
|
| 31 |
|
|
|
|
| 32 |
proxy_read_timeout 86400;
|
| 33 |
proxy_redirect off;
|
| 34 |
}
|
| 35 |
|
| 36 |
|
| 37 |
# ------------------------------------------------
|
| 38 |
+
# 2. Xử lý Chuyển hướng BẮT BUỘC cho Streamlit
|
| 39 |
+
# ------------------------------------------------
|
| 40 |
+
|
| 41 |
+
# Nếu người dùng truy cập KHÔNG có / ở cuối, buộc chuyển hướng sang có /.
|
| 42 |
+
location = /streamlit {
|
| 43 |
+
return 302 /streamlit/;
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
# ------------------------------------------------
|
| 48 |
+
# 3. Định tuyến cho STREAMLIT (Endpoint /streamlit/)
|
| 49 |
# ------------------------------------------------
|
| 50 |
|
|
|
|
| 51 |
location /streamlit/ {
|
| 52 |
+
# HEADER quan trọng cho Streamlit để nhận biết đường dẫn subpath
|
| 53 |
+
proxy_set_header X-Script-Name /streamlit;
|
| 54 |
+
|
| 55 |
+
# KHÔNG DÙNG DẤU / Ở CUỐI: Chuyển tiếp nguyên văn mọi thứ bắt đầu bằng /streamlit/
|
| 56 |
+
proxy_pass http://localhost:8501;
|
| 57 |
+
|
| 58 |
+
# Cấu hình WebSockets
|
| 59 |
proxy_http_version 1.1;
|
| 60 |
proxy_set_header Upgrade $http_upgrade;
|
| 61 |
proxy_set_header Connection 'upgrade';
|
| 62 |
+
|
| 63 |
+
# Headers chuẩn
|
| 64 |
proxy_set_header Host $host;
|
| 65 |
proxy_set_header X-Real-IP $remote_addr;
|
| 66 |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
| 67 |
proxy_cache_bypass $http_upgrade;
|
| 68 |
|
|
|
|
| 69 |
proxy_read_timeout 86400;
|
| 70 |
proxy_redirect off;
|
| 71 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
}
|