Create nginx.conf
Browse files- nginx.conf +63 -0
nginx.conf
ADDED
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
worker_processes 1;
|
2 |
+
|
3 |
+
# 将 Nginx 错误日志输出到标准错误流,方便在 HF Space Logs 查看
|
4 |
+
# 如果日志量太大或不需要,可以改为 error_log /dev/null crit;
|
5 |
+
error_log stderr warn;
|
6 |
+
|
7 |
+
events {
|
8 |
+
worker_connections 1024;
|
9 |
+
}
|
10 |
+
|
11 |
+
http {
|
12 |
+
# 禁用访问日志,如果需要调试可以改为 access_log /dev/stdout;
|
13 |
+
access_log off;
|
14 |
+
|
15 |
+
server {
|
16 |
+
# 监听 HF Space 默认暴露的 7860 端口
|
17 |
+
listen 7860;
|
18 |
+
# 接受所有指向这个 Space 的域名请求
|
19 |
+
server_name _;
|
20 |
+
|
21 |
+
# 处理 /ai/ 前缀的请求
|
22 |
+
location /ai/ {
|
23 |
+
# proxy_pass 目标 URL 末尾必须加斜杠 /,这会告诉 Nginx
|
24 |
+
# 将匹配 location 的部分 (/ai/) 替换掉,并将剩余路径附加到目标 URL 后
|
25 |
+
proxy_pass https://cc.cwapi.me/; # 转发到你的域名 (使用 HTTPS)
|
26 |
+
|
27 |
+
# --- 推荐的代理头部设置 ---
|
28 |
+
# 将 Host 头设置为后端服务器期望的域名
|
29 |
+
proxy_set_header Host cc.cwapi.me;
|
30 |
+
# 传递客户端真实 IP 和协议信息
|
31 |
+
proxy_set_header X-Real-IP $remote_addr;
|
32 |
+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
33 |
+
proxy_set_header X-Forwarded-Proto $scheme;
|
34 |
+
# 使用 HTTP/1.1 与后端通信,并处理好 Connection 头
|
35 |
+
proxy_http_version 1.1;
|
36 |
+
proxy_set_header Connection "";
|
37 |
+
# --- 结束设置 ---
|
38 |
+
|
39 |
+
# 可选:为 AI 请求设置更长的超时时间 (单位:秒)
|
40 |
+
# proxy_connect_timeout 60s;
|
41 |
+
# proxy_send_timeout 60s;
|
42 |
+
# proxy_read_timeout 300s; # 读取后端响应的超时,可能需要长一些
|
43 |
+
}
|
44 |
+
|
45 |
+
# 处理 /cw/ 前缀的请求 (配置逻辑同上)
|
46 |
+
location /cw/ {
|
47 |
+
proxy_pass https://cc.cwapi.me/; # 同样转发到你的域名
|
48 |
+
proxy_set_header Host cc.cwapi.me;
|
49 |
+
proxy_set_header X-Real-IP $remote_addr;
|
50 |
+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
51 |
+
proxy_set_header X-Forwarded-Proto $scheme;
|
52 |
+
proxy_http_version 1.1;
|
53 |
+
proxy_set_header Connection "";
|
54 |
+
}
|
55 |
+
|
56 |
+
# 对于其他所有路径 (比如直接访问根路径 /)
|
57 |
+
location / {
|
58 |
+
# 可以返回一个 404 Not Found,或者一个简单的成功提示
|
59 |
+
return 404 'Not Found: Invalid path. Use /ai/ or /cw/ prefix.';
|
60 |
+
# 或者 return 200 'Nginx Proxy Active';
|
61 |
+
}
|
62 |
+
}
|
63 |
+
}
|