eienmojiki commited on
Commit
078b905
·
verified ·
1 Parent(s): 8377fdf

Update nginx.conf

Browse files
Files changed (1) hide show
  1. 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
- # 1. Định tuyến cho GRADIO (chạy trên 7860)
8
- location /gradio {
9
- rewrite /gradio/(.*) /$1 break;
10
- proxy_pass http://localhost:7860;
 
 
 
 
 
 
11
 
12
- # Cần các header sau cho cả Gradio và Streamlit
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
- proxy_read_timeout 86400; # Tăng timeout cho các tác vụ ML
 
 
 
21
  }
22
-
23
- # 2. Định tuyến cho STREAMLIT (chạy trên 8501)
24
- location /streamlit {
25
- rewrite /streamlit/(.*) /$1 break;
26
- proxy_pass http://localhost:8501;
 
 
 
 
 
 
27
 
28
- # Cấu hình tương tự cho Streamlit
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
- # 3. Yêu cầu root (/) chuyển hướng tới Gradio hoặc Streamlit
 
 
 
 
 
40
  location / {
41
- return 302 /gradio/; # Chọn một ứng dụng để làm mặc định
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 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
  }