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

Update nginx.conf

Browse files
Files changed (1) hide show
  1. 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. Xử 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 / 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 RẤT QUAN TRỌNG
33
- # đả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';
 
 
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ử 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
  }