Spaces:
Sleeping
Sleeping
Update nginx.conf
Browse files- nginx.conf +57 -14
nginx.conf
CHANGED
|
@@ -1,31 +1,66 @@
|
|
| 1 |
server {
|
|
|
|
| 2 |
listen 4444 default_server;
|
| 3 |
listen [::]:4444 default_server;
|
| 4 |
|
| 5 |
server_name _;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
-
#
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
-
#
|
| 13 |
proxy_http_version 1.1;
|
| 14 |
proxy_set_header Upgrade $http_upgrade;
|
| 15 |
proxy_set_header Connection 'upgrade';
|
|
|
|
|
|
|
| 16 |
proxy_set_header Host $host;
|
| 17 |
proxy_set_header X-Real-IP $remote_addr;
|
| 18 |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
| 19 |
proxy_cache_bypass $http_upgrade;
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
| 21 |
}
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
-
# Cấu hình
|
| 29 |
proxy_http_version 1.1;
|
| 30 |
proxy_set_header Upgrade $http_upgrade;
|
| 31 |
proxy_set_header Connection 'upgrade';
|
|
@@ -33,11 +68,19 @@ server {
|
|
| 33 |
proxy_set_header X-Real-IP $remote_addr;
|
| 34 |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
| 35 |
proxy_cache_bypass $http_upgrade;
|
|
|
|
|
|
|
| 36 |
proxy_read_timeout 86400;
|
|
|
|
| 37 |
}
|
| 38 |
|
| 39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
location / {
|
| 41 |
-
return 302 /gradio/; #
|
| 42 |
}
|
| 43 |
}
|
|
|
|
| 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. Xử lý Chuyển hướng BẮT BUỘC (Required Redirects)
|
| 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 |
+
# Nếu người dùng truy cập /streamlit (KHÔNG có / ở cuối),
|
| 19 |
+
# Nginx sẽ trả về HTTP 302 để chuyển hướng họ đến /streamlit/.
|
| 20 |
+
location = /streamlit {
|
| 21 |
+
return 302 /streamlit/;
|
| 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 gạch chéo (/) cuối URL proxy_pass là RẤT QUAN TRỌNG
|
| 33 |
+
# Nó đảm bảo /gradio/xyz được chuyển thành /xyz khi gửi đến backend
|
| 34 |
+
proxy_pass http://localhost:7860/;
|
| 35 |
|
| 36 |
+
# Cấu hình cần thiết cho WebSockets (quan trọng cho cả Gradio và Streamlit)
|
| 37 |
proxy_http_version 1.1;
|
| 38 |
proxy_set_header Upgrade $http_upgrade;
|
| 39 |
proxy_set_header Connection 'upgrade';
|
| 40 |
+
|
| 41 |
+
# Các headers chuẩn
|
| 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 |
+
# 3. Định tuyến cho STREAMLIT (Sau khi đã có dấu /)
|
| 55 |
+
# ------------------------------------------------
|
| 56 |
+
|
| 57 |
+
# Khớp với /streamlit/ và mọi thứ theo sau
|
| 58 |
+
location /streamlit/ {
|
| 59 |
+
# Proxy_pass đến cổng 8501 (Streamlit)
|
| 60 |
+
# Dấu gạch chéo (/) cuối URL proxy_pass là RẤT QUAN TRỌNG
|
| 61 |
+
proxy_pass http://localhost:8501/;
|
| 62 |
|
| 63 |
+
# Cấu hình WebSockets và Headers chuẩn
|
| 64 |
proxy_http_version 1.1;
|
| 65 |
proxy_set_header Upgrade $http_upgrade;
|
| 66 |
proxy_set_header Connection 'upgrade';
|
|
|
|
| 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 |
}
|