update
Browse files- README.md +38 -15
- nginx/conf.d/default.conf +39 -583
- test-nginx-config.sh +62 -0
README.md
CHANGED
|
@@ -45,19 +45,25 @@ curl -u admin:admin123 https://airsltd-ocngx.hf.space/
|
|
| 45 |
curl -u admin:admin123 https://airsltd-ocngx.hf.space/health
|
| 46 |
```
|
| 47 |
|
| 48 |
-
#### 3. OpenCode
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
```bash
|
| 50 |
# API 文档
|
| 51 |
-
curl -u admin:admin123 https://airsltd-ocngx.hf.space/opencode/doc
|
| 52 |
|
| 53 |
# OpenCode 健康检查
|
| 54 |
-
curl -u admin:admin123 https://airsltd-ocngx.hf.space/opencode/global/health
|
| 55 |
|
| 56 |
# 创建 AI 编程会话
|
| 57 |
curl -u admin:admin123 -X POST \
|
| 58 |
-H "Content-Type: application/json" \
|
| 59 |
-d '{"title": "AI Coding Session"}' \
|
| 60 |
-
https://airsltd-ocngx.hf.space/opencode/session
|
| 61 |
|
| 62 |
# 发送 AI 请求
|
| 63 |
curl -u admin:admin123 -X POST \
|
|
@@ -65,7 +71,7 @@ curl -u admin:admin123 -X POST \
|
|
| 65 |
-d '{
|
| 66 |
"parts": [{"type": "text", "text": "创建一个 Python Hello World 应用"}]
|
| 67 |
}' \
|
| 68 |
-
https://airsltd-ocngx.hf.space/opencode/session/{session_id}/message
|
| 69 |
```
|
| 70 |
|
| 71 |
## 📋 API 端点
|
|
@@ -74,29 +80,29 @@ curl -u admin:admin123 -X POST \
|
|
| 74 |
|
| 75 |
| 端点 | 方法 | 描述 |
|
| 76 |
|------|------|------|
|
| 77 |
-
| `/` | GET | 主页和介绍 |
|
| 78 |
| `/health` | GET | 服务健康检查 |
|
| 79 |
-
| `/opencode/
|
| 80 |
-
| `/opencode/*` | ALL | OpenCode API 代理 |
|
| 81 |
|
| 82 |
### 🤖 OpenCode API
|
| 83 |
|
| 84 |
#### 核心 API
|
| 85 |
```bash
|
| 86 |
# 健康检查
|
| 87 |
-
curl -u admin:admin123 https://airsltd-ocngx.hf.space/opencode/global/health
|
| 88 |
|
| 89 |
# API 文档
|
| 90 |
-
curl -u admin:admin123 https://airsltd-ocngx.hf.space/opencode/doc
|
| 91 |
|
| 92 |
# 项目管理
|
| 93 |
-
curl -u admin:admin123 https://airsltd-ocngx.hf.space/opencode/project
|
| 94 |
|
| 95 |
# 会话管理
|
| 96 |
-
curl -u admin:admin123 https://airsltd-ocngx.hf.space/opencode/session
|
| 97 |
|
| 98 |
# 提供商管理
|
| 99 |
-
curl -u admin:admin123 https://airsltd-ocngx.hf.space/opencode/provider
|
| 100 |
```
|
| 101 |
|
| 102 |
#### Nginx 原生端点
|
|
@@ -113,10 +119,27 @@ curl -u admin:admin123 https://airsltd-ocngx.hf.space/health
|
|
| 113 |
```
|
| 114 |
用户请求 → Nginx (7860) → OpenCode (57860) → AI 模型
|
| 115 |
↓ ↓ ↓
|
| 116 |
-
|
| 117 |
-
|
| 118 |
```
|
| 119 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 120 |
### 🔧 组件说明
|
| 121 |
|
| 122 |
1. **Nginx 服务器**
|
|
|
|
| 45 |
curl -u admin:admin123 https://airsltd-ocngx.hf.space/health
|
| 46 |
```
|
| 47 |
|
| 48 |
+
#### 3. OpenCode Web界面
|
| 49 |
+
```bash
|
| 50 |
+
# 访问OpenCode Web界面
|
| 51 |
+
curl -u admin:admin123 https://airsltd-ocngx.hf.space/opencode/web/
|
| 52 |
+
```
|
| 53 |
+
|
| 54 |
+
#### 4. OpenCode API (通过代理)
|
| 55 |
```bash
|
| 56 |
# API 文档
|
| 57 |
+
curl -u admin:admin123 https://airsltd-ocngx.hf.space/opencode/api/doc
|
| 58 |
|
| 59 |
# OpenCode 健康检查
|
| 60 |
+
curl -u admin:admin123 https://airsltd-ocngx.hf.space/opencode/api/global/health
|
| 61 |
|
| 62 |
# 创建 AI 编程会话
|
| 63 |
curl -u admin:admin123 -X POST \
|
| 64 |
-H "Content-Type: application/json" \
|
| 65 |
-d '{"title": "AI Coding Session"}' \
|
| 66 |
+
https://airsltd-ocngx.hf.space/opencode/api/session
|
| 67 |
|
| 68 |
# 发送 AI 请求
|
| 69 |
curl -u admin:admin123 -X POST \
|
|
|
|
| 71 |
-d '{
|
| 72 |
"parts": [{"type": "text", "text": "创建一个 Python Hello World 应用"}]
|
| 73 |
}' \
|
| 74 |
+
https://airsltd-ocngx.hf.space/opencode/api/session/{session_id}/message
|
| 75 |
```
|
| 76 |
|
| 77 |
## 📋 API 端点
|
|
|
|
| 80 |
|
| 81 |
| 端点 | 方法 | 描述 |
|
| 82 |
|------|------|------|
|
| 83 |
+
| `/` | GET | nginx主页和介绍 |
|
| 84 |
| `/health` | GET | 服务健康检查 |
|
| 85 |
+
| `/opencode/web/` | GET | OpenCode Web界面 |
|
| 86 |
+
| `/opencode/api/*` | ALL | OpenCode API 代理 |
|
| 87 |
|
| 88 |
### 🤖 OpenCode API
|
| 89 |
|
| 90 |
#### 核心 API
|
| 91 |
```bash
|
| 92 |
# 健康检查
|
| 93 |
+
curl -u admin:admin123 https://airsltd-ocngx.hf.space/opencode/api/global/health
|
| 94 |
|
| 95 |
# API 文档
|
| 96 |
+
curl -u admin:admin123 https://airsltd-ocngx.hf.space/opencode/api/doc
|
| 97 |
|
| 98 |
# 项目管理
|
| 99 |
+
curl -u admin:admin123 https://airsltd-ocngx.hf.space/opencode/api/project
|
| 100 |
|
| 101 |
# 会话管理
|
| 102 |
+
curl -u admin:admin123 https://airsltd-ocngx.hf.space/opencode/api/session
|
| 103 |
|
| 104 |
# 提供商管理
|
| 105 |
+
curl -u admin:admin123 https://airsltd-ocngx.hf.space/opencode/api/provider
|
| 106 |
```
|
| 107 |
|
| 108 |
#### Nginx 原生端点
|
|
|
|
| 119 |
```
|
| 120 |
用户请求 → Nginx (7860) → OpenCode (57860) → AI 模型
|
| 121 |
↓ ↓ ↓
|
| 122 |
+
Basic Auth → 统一代理 → AI 处理
|
| 123 |
+
Lua 过滤 → 路径重写 → 代码生成
|
| 124 |
```
|
| 125 |
|
| 126 |
+
### 🔧 新架构特性
|
| 127 |
+
|
| 128 |
+
1. **统一认证**
|
| 129 |
+
- Server级别HTTP Basic Auth
|
| 130 |
+
- 一次登录,全局访问
|
| 131 |
+
- 无需重复认证
|
| 132 |
+
|
| 133 |
+
2. **路径分离**
|
| 134 |
+
- `/` - nginx默认站点
|
| 135 |
+
- `/opencode/web/` - OpenCode Web界面
|
| 136 |
+
- `/opencode/api/` - OpenCode API端点
|
| 137 |
+
|
| 138 |
+
3. **简化代理**
|
| 139 |
+
- 统一端点转发
|
| 140 |
+
- 减少配置复杂度
|
| 141 |
+
- 自动路径重写
|
| 142 |
+
|
| 143 |
### 🔧 组件说明
|
| 144 |
|
| 145 |
1. **Nginx 服务器**
|
nginx/conf.d/default.conf
CHANGED
|
@@ -5,22 +5,23 @@ server {
|
|
| 5 |
# 在Hugging Face Spaces环境中,重定向时不包含端口号
|
| 6 |
absolute_redirect off;
|
| 7 |
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
auth_basic_user_file /usr/local/openresty/nginx/conf/.htpasswd;
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
|
|
|
|
|
|
|
| 24 |
root /usr/local/openresty/nginx/html;
|
| 25 |
index index.html index.htm;
|
| 26 |
|
|
@@ -35,117 +36,12 @@ server {
|
|
| 35 |
add_header Content-Type text/plain;
|
| 36 |
}
|
| 37 |
|
| 38 |
-
# OpenCode
|
| 39 |
-
location /
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
proxy_set_header X-Real-IP $remote_addr;
|
| 43 |
-
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
| 44 |
-
proxy_set_header X-Forwarded-Proto $scheme;
|
| 45 |
-
}
|
| 46 |
-
|
| 47 |
-
location /oc-theme-preload.js {
|
| 48 |
-
proxy_pass http://127.0.0.1:57860;
|
| 49 |
-
proxy_set_header Host $host;
|
| 50 |
-
proxy_set_header X-Real-IP $remote_addr;
|
| 51 |
-
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
| 52 |
-
proxy_set_header X-Forwarded-Proto $scheme;
|
| 53 |
-
}
|
| 54 |
-
|
| 55 |
-
location /site.webmanifest {
|
| 56 |
-
proxy_pass http://127.0.0.1:57860;
|
| 57 |
-
proxy_set_header Host $host;
|
| 58 |
-
proxy_set_header X-Real-IP $remote_addr;
|
| 59 |
-
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
| 60 |
-
proxy_set_header X-Forwarded-Proto $scheme;
|
| 61 |
-
}
|
| 62 |
-
|
| 63 |
-
# OpenCode favicon 和图标资源
|
| 64 |
-
location ~ ^/(favicon.*\.(png|svg|ico)|apple-touch-icon\.png)$ {
|
| 65 |
-
proxy_pass http://127.0.0.1:57860;
|
| 66 |
-
proxy_set_header Host $host;
|
| 67 |
-
proxy_set_header X-Real-IP $remote_addr;
|
| 68 |
-
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
| 69 |
-
proxy_set_header X-Forwarded-Proto $scheme;
|
| 70 |
-
}
|
| 71 |
-
|
| 72 |
-
# OpenCode API 端点代理 - 处理所有相对路径的API调用
|
| 73 |
-
location /global/ {
|
| 74 |
-
proxy_pass http://127.0.0.1:57860;
|
| 75 |
-
proxy_set_header Host $host;
|
| 76 |
-
proxy_set_header X-Real-IP $remote_addr;
|
| 77 |
-
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
| 78 |
-
proxy_set_header X-Forwarded-Proto $scheme;
|
| 79 |
-
|
| 80 |
-
# 处理 CORS
|
| 81 |
-
add_header Access-Control-Allow-Origin * always;
|
| 82 |
-
add_header Access-Control-Allow-Methods "GET, POST, PUT, DELETE, PATCH, OPTIONS" always;
|
| 83 |
-
add_header Access-Control-Allow-Headers "Content-Type, Authorization, X-Requested-With" always;
|
| 84 |
-
add_header Access-Control-Expose-Headers "Content-Type, Content-Length" always;
|
| 85 |
-
|
| 86 |
-
# 支持流式响应和 SSE
|
| 87 |
-
proxy_buffering off;
|
| 88 |
-
proxy_cache off;
|
| 89 |
-
proxy_set_header Connection '';
|
| 90 |
-
proxy_http_version 1.1;
|
| 91 |
-
chunked_transfer_encoding on;
|
| 92 |
-
|
| 93 |
-
# 超时设置
|
| 94 |
-
proxy_connect_timeout 60s;
|
| 95 |
-
proxy_send_timeout 300s;
|
| 96 |
-
}
|
| 97 |
-
|
| 98 |
-
location /session {
|
| 99 |
-
proxy_pass http://127.0.0.1:57860;
|
| 100 |
-
proxy_set_header Host $host;
|
| 101 |
-
proxy_set_header X-Real-IP $remote_addr;
|
| 102 |
-
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
| 103 |
-
proxy_set_header X-Forwarded-Proto $scheme;
|
| 104 |
-
|
| 105 |
-
# 处理 CORS
|
| 106 |
-
add_header Access-Control-Allow-Origin * always;
|
| 107 |
-
add_header Access-Control-Allow-Methods "GET, POST, PUT, DELETE, PATCH, OPTIONS" always;
|
| 108 |
-
add_header Access-Control-Allow-Headers "Content-Type, Authorization, X-Requested-With" always;
|
| 109 |
-
add_header Access-Control-Expose-Headers "Content-Type, Content-Length" always;
|
| 110 |
-
|
| 111 |
-
# 支持流式响应和 SSE
|
| 112 |
-
proxy_buffering off;
|
| 113 |
-
proxy_cache off;
|
| 114 |
-
proxy_set_header Connection '';
|
| 115 |
-
proxy_http_version 1.1;
|
| 116 |
-
chunked_transfer_encoding on;
|
| 117 |
-
|
| 118 |
-
# 超时设置
|
| 119 |
-
proxy_connect_timeout 60s;
|
| 120 |
-
proxy_send_timeout 300s;
|
| 121 |
-
}
|
| 122 |
-
|
| 123 |
-
location /project {
|
| 124 |
-
proxy_pass http://127.0.0.1:57860;
|
| 125 |
-
proxy_set_header Host $host;
|
| 126 |
-
proxy_set_header X-Real-IP $remote_addr;
|
| 127 |
-
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
| 128 |
-
proxy_set_header X-Forwarded-Proto $scheme;
|
| 129 |
-
|
| 130 |
-
# 处理 CORS
|
| 131 |
-
add_header Access-Control-Allow-Origin * always;
|
| 132 |
-
add_header Access-Control-Allow-Methods "GET, POST, PUT, DELETE, PATCH, OPTIONS" always;
|
| 133 |
-
add_header Access-Control-Allow-Headers "Content-Type, Authorization, X-Requested-With" always;
|
| 134 |
-
add_header Access-Control-Expose-Headers "Content-Type, Content-Length" always;
|
| 135 |
-
|
| 136 |
-
# 支持流式响应和 SSE
|
| 137 |
-
proxy_buffering off;
|
| 138 |
-
proxy_cache off;
|
| 139 |
-
proxy_set_header Connection '';
|
| 140 |
-
proxy_http_version 1.1;
|
| 141 |
-
chunked_transfer_encoding on;
|
| 142 |
|
| 143 |
-
#
|
| 144 |
-
proxy_connect_timeout 60s;
|
| 145 |
-
proxy_send_timeout 300s;
|
| 146 |
-
}
|
| 147 |
-
|
| 148 |
-
location /provider {
|
| 149 |
proxy_pass http://127.0.0.1:57860;
|
| 150 |
proxy_set_header Host $host;
|
| 151 |
proxy_set_header X-Real-IP $remote_addr;
|
|
@@ -169,33 +65,13 @@ server {
|
|
| 169 |
proxy_connect_timeout 60s;
|
| 170 |
proxy_send_timeout 300s;
|
| 171 |
}
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
| 178 |
-
proxy_set_header X-Forwarded-Proto $scheme;
|
| 179 |
-
|
| 180 |
-
# 处理 CORS
|
| 181 |
-
add_header Access-Control-Allow-Origin * always;
|
| 182 |
-
add_header Access-Control-Allow-Methods "GET, POST, PUT, DELETE, PATCH, OPTIONS" always;
|
| 183 |
-
add_header Access-Control-Allow-Headers "Content-Type, Authorization, X-Requested-With" always;
|
| 184 |
-
add_header Access-Control-Expose-Headers "Content-Type, Content-Length" always;
|
| 185 |
-
|
| 186 |
-
# 支持流式响应和 SSE
|
| 187 |
-
proxy_buffering off;
|
| 188 |
-
proxy_cache off;
|
| 189 |
-
proxy_set_header Connection '';
|
| 190 |
-
proxy_http_version 1.1;
|
| 191 |
-
chunked_transfer_encoding on;
|
| 192 |
|
| 193 |
-
#
|
| 194 |
-
proxy_connect_timeout 60s;
|
| 195 |
-
proxy_send_timeout 300s;
|
| 196 |
-
}
|
| 197 |
-
|
| 198 |
-
location /find {
|
| 199 |
proxy_pass http://127.0.0.1:57860;
|
| 200 |
proxy_set_header Host $host;
|
| 201 |
proxy_set_header X-Real-IP $remote_addr;
|
|
@@ -219,468 +95,48 @@ server {
|
|
| 219 |
proxy_connect_timeout 60s;
|
| 220 |
proxy_send_timeout 300s;
|
| 221 |
}
|
| 222 |
-
|
| 223 |
-
|
|
|
|
| 224 |
proxy_pass http://127.0.0.1:57860;
|
| 225 |
proxy_set_header Host $host;
|
| 226 |
proxy_set_header X-Real-IP $remote_addr;
|
| 227 |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
| 228 |
proxy_set_header X-Forwarded-Proto $scheme;
|
| 229 |
-
|
| 230 |
-
# 处理 CORS
|
| 231 |
-
add_header Access-Control-Allow-Origin * always;
|
| 232 |
-
add_header Access-Control-Allow-Methods "GET, POST, PUT, DELETE, PATCH, OPTIONS" always;
|
| 233 |
-
add_header Access-Control-Allow-Headers "Content-Type, Authorization, X-Requested-With" always;
|
| 234 |
-
add_header Access-Control-Expose-Headers "Content-Type, Content-Length" always;
|
| 235 |
-
|
| 236 |
-
# 支持流式响应和 SSE
|
| 237 |
-
proxy_buffering off;
|
| 238 |
-
proxy_cache off;
|
| 239 |
-
proxy_set_header Connection '';
|
| 240 |
-
proxy_http_version 1.1;
|
| 241 |
-
chunked_transfer_encoding on;
|
| 242 |
-
|
| 243 |
-
# 超时设置
|
| 244 |
-
proxy_connect_timeout 60s;
|
| 245 |
-
proxy_send_timeout 300s;
|
| 246 |
}
|
| 247 |
|
| 248 |
-
location /
|
| 249 |
proxy_pass http://127.0.0.1:57860;
|
| 250 |
proxy_set_header Host $host;
|
| 251 |
proxy_set_header X-Real-IP $remote_addr;
|
| 252 |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
| 253 |
proxy_set_header X-Forwarded-Proto $scheme;
|
| 254 |
-
|
| 255 |
-
# 处理 CORS
|
| 256 |
-
add_header Access-Control-Allow-Origin * always;
|
| 257 |
-
add_header Access-Control-Allow-Methods "GET, POST, PUT, DELETE, PATCH, OPTIONS" always;
|
| 258 |
-
add_header Access-Control-Allow-Headers "Content-Type, Authorization, X-Requested-With" always;
|
| 259 |
-
add_header Access-Control-Expose-Headers "Content-Type, Content-Length" always;
|
| 260 |
-
|
| 261 |
-
# 支持流式响应和 SSE
|
| 262 |
-
proxy_buffering off;
|
| 263 |
-
proxy_cache off;
|
| 264 |
-
proxy_set_header Connection '';
|
| 265 |
-
proxy_http_version 1.1;
|
| 266 |
-
chunked_transfer_encoding on;
|
| 267 |
-
|
| 268 |
-
# 超时设置
|
| 269 |
-
proxy_connect_timeout 60s;
|
| 270 |
-
proxy_send_timeout 300s;
|
| 271 |
}
|
| 272 |
|
| 273 |
-
location /
|
| 274 |
proxy_pass http://127.0.0.1:57860;
|
| 275 |
proxy_set_header Host $host;
|
| 276 |
proxy_set_header X-Real-IP $remote_addr;
|
| 277 |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
| 278 |
proxy_set_header X-Forwarded-Proto $scheme;
|
| 279 |
-
|
| 280 |
-
# 处理 CORS
|
| 281 |
-
add_header Access-Control-Allow-Origin * always;
|
| 282 |
-
add_header Access-Control-Allow-Methods "GET, POST, PUT, DELETE, PATCH, OPTIONS" always;
|
| 283 |
-
add_header Access-Control-Allow-Headers "Content-Type, Authorization, X-Requested-With" always;
|
| 284 |
-
add_header Access-Control-Expose-Headers "Content-Type, Content-Length" always;
|
| 285 |
-
|
| 286 |
-
# 支持流式响应和 SSE
|
| 287 |
-
proxy_buffering off;
|
| 288 |
-
proxy_cache off;
|
| 289 |
-
proxy_set_header Connection '';
|
| 290 |
-
proxy_http_version 1.1;
|
| 291 |
-
chunked_transfer_encoding on;
|
| 292 |
-
|
| 293 |
-
# 超时设置
|
| 294 |
-
proxy_connect_timeout 60s;
|
| 295 |
-
proxy_send_timeout 300s;
|
| 296 |
}
|
| 297 |
|
| 298 |
-
|
|
|
|
| 299 |
proxy_pass http://127.0.0.1:57860;
|
| 300 |
proxy_set_header Host $host;
|
| 301 |
proxy_set_header X-Real-IP $remote_addr;
|
| 302 |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
| 303 |
proxy_set_header X-Forwarded-Proto $scheme;
|
| 304 |
-
|
| 305 |
-
# 处理 CORS
|
| 306 |
-
add_header Access-Control-Allow-Origin * always;
|
| 307 |
-
add_header Access-Control-Allow-Methods "GET, POST, PUT, DELETE, PATCH, OPTIONS" always;
|
| 308 |
-
add_header Access-Control-Allow-Headers "Content-Type, Authorization, X-Requested-With" always;
|
| 309 |
-
add_header Access-Control-Expose-Headers "Content-Type, Content-Length" always;
|
| 310 |
-
|
| 311 |
-
# 支持流式响应和 SSE
|
| 312 |
-
proxy_buffering off;
|
| 313 |
-
proxy_cache off;
|
| 314 |
-
proxy_set_header Connection '';
|
| 315 |
-
proxy_http_version 1.1;
|
| 316 |
-
chunked_transfer_encoding on;
|
| 317 |
-
|
| 318 |
-
# 超时设置
|
| 319 |
-
proxy_connect_timeout 60s;
|
| 320 |
-
proxy_send_timeout 300s;
|
| 321 |
}
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
proxy_set_header X-Real-IP $remote_addr;
|
| 327 |
-
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
| 328 |
-
proxy_set_header X-Forwarded-Proto $scheme;
|
| 329 |
-
|
| 330 |
-
# 处理 CORS
|
| 331 |
-
add_header Access-Control-Allow-Origin * always;
|
| 332 |
-
add_header Access-Control-Allow-Methods "GET, POST, PUT, DELETE, PATCH, OPTIONS" always;
|
| 333 |
-
add_header Access-Control-Allow-Headers "Content-Type, Authorization, X-Requested-With" always;
|
| 334 |
-
add_header Access-Control-Expose-Headers "Content-Type, Content-Length" always;
|
| 335 |
-
|
| 336 |
-
# 支持流式响应和 SSE
|
| 337 |
-
proxy_buffering off;
|
| 338 |
-
proxy_cache off;
|
| 339 |
-
proxy_set_header Connection '';
|
| 340 |
-
proxy_http_version 1.1;
|
| 341 |
-
chunked_transfer_encoding on;
|
| 342 |
-
|
| 343 |
-
# 超时设置
|
| 344 |
-
proxy_connect_timeout 60s;
|
| 345 |
-
proxy_send_timeout 300s;
|
| 346 |
}
|
| 347 |
|
| 348 |
-
location /
|
| 349 |
-
|
| 350 |
-
proxy_set_header Host $host;
|
| 351 |
-
proxy_set_header X-Real-IP $remote_addr;
|
| 352 |
-
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
| 353 |
-
proxy_set_header X-Forwarded-Proto $scheme;
|
| 354 |
-
|
| 355 |
-
# 处理 CORS
|
| 356 |
-
add_header Access-Control-Allow-Origin * always;
|
| 357 |
-
add_header Access-Control-Allow-Methods "GET, POST, PUT, DELETE, PATCH, OPTIONS" always;
|
| 358 |
-
add_header Access-Control-Allow-Headers "Content-Type, Authorization, X-Requested-With" always;
|
| 359 |
-
add_header Access-Control-Expose-Headers "Content-Type, Content-Length" always;
|
| 360 |
-
|
| 361 |
-
# 支持流式响应和 SSE
|
| 362 |
-
proxy_buffering off;
|
| 363 |
-
proxy_cache off;
|
| 364 |
-
proxy_set_header Connection '';
|
| 365 |
-
proxy_http_version 1.1;
|
| 366 |
-
chunked_transfer_encoding on;
|
| 367 |
-
|
| 368 |
-
# 超时设置
|
| 369 |
-
proxy_connect_timeout 60s;
|
| 370 |
-
proxy_send_timeout 300s;
|
| 371 |
-
}
|
| 372 |
-
|
| 373 |
-
location /doc {
|
| 374 |
-
proxy_pass http://127.0.0.1:57860;
|
| 375 |
-
proxy_set_header Host $host;
|
| 376 |
-
proxy_set_header X-Real-IP $remote_addr;
|
| 377 |
-
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
| 378 |
-
proxy_set_header X-Forwarded-Proto $scheme;
|
| 379 |
-
|
| 380 |
-
# 处理 CORS
|
| 381 |
-
add_header Access-Control-Allow-Origin * always;
|
| 382 |
-
add_header Access-Control-Allow-Methods "GET, POST, PUT, DELETE, PATCH, OPTIONS" always;
|
| 383 |
-
add_header Access-Control-Allow-Headers "Content-Type, Authorization, X-Requested-With" always;
|
| 384 |
-
add_header Access-Control-Expose-Headers "Content-Type, Content-Length" always;
|
| 385 |
-
|
| 386 |
-
# 支持流式响应和 SSE
|
| 387 |
-
proxy_buffering off;
|
| 388 |
-
proxy_cache off;
|
| 389 |
-
proxy_set_header Connection '';
|
| 390 |
-
proxy_http_version 1.1;
|
| 391 |
-
chunked_transfer_encoding on;
|
| 392 |
-
|
| 393 |
-
# 超时设置
|
| 394 |
-
proxy_connect_timeout 60s;
|
| 395 |
-
proxy_send_timeout 300s;
|
| 396 |
-
}
|
| 397 |
-
|
| 398 |
-
location /lsp {
|
| 399 |
-
proxy_pass http://127.0.0.1:57860;
|
| 400 |
-
proxy_set_header Host $host;
|
| 401 |
-
proxy_set_header X-Real-IP $remote_addr;
|
| 402 |
-
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
| 403 |
-
proxy_set_header X-Forwarded-Proto $scheme;
|
| 404 |
-
|
| 405 |
-
# 处理 CORS
|
| 406 |
-
add_header Access-Control-Allow-Origin * always;
|
| 407 |
-
add_header Access-Control-Allow-Methods "GET, POST, PUT, DELETE, PATCH, OPTIONS" always;
|
| 408 |
-
add_header Access-Control-Allow-Headers "Content-Type, Authorization, X-Requested-With" always;
|
| 409 |
-
add_header Access-Control-Expose-Headers "Content-Type, Content-Length" always;
|
| 410 |
-
|
| 411 |
-
# 支持流式响应和 SSE
|
| 412 |
-
proxy_buffering off;
|
| 413 |
-
proxy_cache off;
|
| 414 |
-
proxy_set_header Connection '';
|
| 415 |
-
proxy_http_version 1.1;
|
| 416 |
-
chunked_transfer_encoding on;
|
| 417 |
-
|
| 418 |
-
# 超时设置
|
| 419 |
-
proxy_connect_timeout 60s;
|
| 420 |
-
proxy_send_timeout 300s;
|
| 421 |
-
}
|
| 422 |
-
|
| 423 |
-
location /mcp {
|
| 424 |
-
proxy_pass http://127.0.0.1:57860;
|
| 425 |
-
proxy_set_header Host $host;
|
| 426 |
-
proxy_set_header X-Real-IP $remote_addr;
|
| 427 |
-
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
| 428 |
-
proxy_set_header X-Forwarded-Proto $scheme;
|
| 429 |
-
|
| 430 |
-
# 处理 CORS
|
| 431 |
-
add_header Access-Control-Allow-Origin * always;
|
| 432 |
-
add_header Access-Control-Allow-Methods "GET, POST, PUT, DELETE, PATCH, OPTIONS" always;
|
| 433 |
-
add_header Access-Control-Allow-Headers "Content-Type, Authorization, X-Requested-With" always;
|
| 434 |
-
add_header Access-Control-Expose-Headers "Content-Type, Content-Length" always;
|
| 435 |
-
|
| 436 |
-
# 支持流式响应和 SSE
|
| 437 |
-
proxy_buffering off;
|
| 438 |
-
proxy_cache off;
|
| 439 |
-
proxy_set_header Connection '';
|
| 440 |
-
proxy_http_version 1.1;
|
| 441 |
-
chunked_transfer_encoding on;
|
| 442 |
-
|
| 443 |
-
# 超时设置
|
| 444 |
-
proxy_connect_timeout 60s;
|
| 445 |
-
proxy_send_timeout 300s;
|
| 446 |
-
}
|
| 447 |
-
|
| 448 |
-
location /permission {
|
| 449 |
-
proxy_pass http://127.0.0.1:57860;
|
| 450 |
-
proxy_set_header Host $host;
|
| 451 |
-
proxy_set_header X-Real-IP $remote_addr;
|
| 452 |
-
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
| 453 |
-
proxy_set_header X-Forwarded-Proto $scheme;
|
| 454 |
-
|
| 455 |
-
# 处理 CORS
|
| 456 |
-
add_header Access-Control-Allow-Origin * always;
|
| 457 |
-
add_header Access-Control-Allow-Methods "GET, POST, PUT, DELETE, PATCH, OPTIONS" always;
|
| 458 |
-
add_header Access-Control-Allow-Headers "Content-Type, Authorization, X-Requested-With" always;
|
| 459 |
-
add_header Access-Control-Expose-Headers "Content-Type, Content-Length" always;
|
| 460 |
-
|
| 461 |
-
# 支持流式响应和 SSE
|
| 462 |
-
proxy_buffering off;
|
| 463 |
-
proxy_cache off;
|
| 464 |
-
proxy_set_header Connection '';
|
| 465 |
-
proxy_http_version 1.1;
|
| 466 |
-
chunked_transfer_encoding on;
|
| 467 |
-
|
| 468 |
-
# 超时设置
|
| 469 |
-
proxy_connect_timeout 60s;
|
| 470 |
-
proxy_send_timeout 300s;
|
| 471 |
-
proxy_read_timeout 300s;
|
| 472 |
-
}
|
| 473 |
-
|
| 474 |
-
location /agent {
|
| 475 |
-
proxy_pass http://127.0.0.1:57860;
|
| 476 |
-
proxy_set_header Host $host;
|
| 477 |
-
proxy_set_header X-Real-IP $remote_addr;
|
| 478 |
-
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
| 479 |
-
proxy_set_header X-Forwarded-Proto $scheme;
|
| 480 |
-
|
| 481 |
-
# 处理 CORS
|
| 482 |
-
add_header Access-Control-Allow-Origin * always;
|
| 483 |
-
add_header Access-Control-Allow-Methods "GET, POST, PUT, DELETE, PATCH, OPTIONS" always;
|
| 484 |
-
add_header Access-Control-Allow-Headers "Content-Type, Authorization, X-Requested-With" always;
|
| 485 |
-
add_header Access-Control-Expose-Headers "Content-Type, Content-Length" always;
|
| 486 |
-
|
| 487 |
-
# 支持流式响应和 SSE
|
| 488 |
-
proxy_buffering off;
|
| 489 |
-
proxy_cache off;
|
| 490 |
-
proxy_set_header Connection '';
|
| 491 |
-
proxy_http_version 1.1;
|
| 492 |
-
chunked_transfer_encoding on;
|
| 493 |
-
|
| 494 |
-
# 超时设置
|
| 495 |
-
proxy_connect_timeout 60s;
|
| 496 |
-
proxy_send_timeout 300s;
|
| 497 |
-
proxy_read_timeout 300s;
|
| 498 |
-
}
|
| 499 |
-
|
| 500 |
-
location /auth {
|
| 501 |
-
proxy_pass http://127.0.0.1:57860;
|
| 502 |
-
proxy_set_header Host $host;
|
| 503 |
-
proxy_set_header X-Real-IP $remote_addr;
|
| 504 |
-
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
| 505 |
-
proxy_set_header X-Forwarded-Proto $scheme;
|
| 506 |
-
|
| 507 |
-
# 处理 CORS
|
| 508 |
-
add_header Access-Control-Allow-Origin * always;
|
| 509 |
-
add_header Access-Control-Allow-Methods "GET, POST, PUT, DELETE, PATCH, OPTIONS" always;
|
| 510 |
-
add_header Access-Control-Allow-Headers "Content-Type, Authorization, X-Requested-With" always;
|
| 511 |
-
add_header Access-Control-Expose-Headers "Content-Type, Content-Length" always;
|
| 512 |
-
|
| 513 |
-
# 支持流式响应和 SSE
|
| 514 |
-
proxy_buffering off;
|
| 515 |
-
proxy_cache off;
|
| 516 |
-
proxy_set_header Connection '';
|
| 517 |
-
proxy_http_version 1.1;
|
| 518 |
-
chunked_transfer_encoding on;
|
| 519 |
-
|
| 520 |
-
# 超时设置
|
| 521 |
-
proxy_connect_timeout 60s;
|
| 522 |
-
proxy_send_timeout 300s;
|
| 523 |
-
}
|
| 524 |
-
|
| 525 |
-
location /command {
|
| 526 |
-
proxy_pass http://127.0.0.1:57860;
|
| 527 |
-
proxy_set_header Host $host;
|
| 528 |
-
proxy_set_header X-Real-IP $remote_addr;
|
| 529 |
-
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
| 530 |
-
proxy_set_header X-Forwarded-Proto $scheme;
|
| 531 |
-
|
| 532 |
-
# 处理 CORS
|
| 533 |
-
add_header Access-Control-Allow-Origin * always;
|
| 534 |
-
add_header Access-Control-Allow-Methods "GET, POST, PUT, DELETE, PATCH, OPTIONS" always;
|
| 535 |
-
add_header Access-Control-Allow-Headers "Content-Type, Authorization, X-Requested-With" always;
|
| 536 |
-
add_header Access-Control-Expose-Headers "Content-Type, Content-Length" always;
|
| 537 |
-
|
| 538 |
-
# 支持流式响应和 SSE
|
| 539 |
-
proxy_buffering off;
|
| 540 |
-
proxy_cache off;
|
| 541 |
-
proxy_set_header Connection '';
|
| 542 |
-
proxy_http_version 1.1;
|
| 543 |
-
chunked_transfer_encoding on;
|
| 544 |
-
|
| 545 |
-
# 超时设置
|
| 546 |
-
proxy_connect_timeout 60s;
|
| 547 |
-
proxy_send_timeout 300s;
|
| 548 |
-
proxy_read_timeout 300s;
|
| 549 |
-
}
|
| 550 |
-
|
| 551 |
-
location /event {
|
| 552 |
-
proxy_pass http://127.0.0.1:57860;
|
| 553 |
-
proxy_set_header Host $host;
|
| 554 |
-
proxy_set_header X-Real-IP $remote_addr;
|
| 555 |
-
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
| 556 |
-
proxy_set_header X-Forwarded-Proto $scheme;
|
| 557 |
-
|
| 558 |
-
# 处理 CORS
|
| 559 |
-
add_header Access-Control-Allow-Origin * always;
|
| 560 |
-
add_header Access-Control-Allow-Methods "GET, POST, PUT, DELETE, PATCH, OPTIONS" always;
|
| 561 |
-
add_header Access-Control-Allow-Headers "Content-Type, Authorization, X-Requested-With" always;
|
| 562 |
-
add_header Access-Control-Expose-Headers "Content-Type, Content-Length" always;
|
| 563 |
-
|
| 564 |
-
# 支持流式响应和 SSE
|
| 565 |
-
proxy_buffering off;
|
| 566 |
-
proxy_cache off;
|
| 567 |
-
proxy_set_header Connection '';
|
| 568 |
-
proxy_http_version 1.1;
|
| 569 |
-
chunked_transfer_encoding on;
|
| 570 |
-
|
| 571 |
-
# 超时设置
|
| 572 |
-
proxy_connect_timeout 60s;
|
| 573 |
-
proxy_send_timeout 300s;
|
| 574 |
-
}
|
| 575 |
-
|
| 576 |
-
location /formatter {
|
| 577 |
-
proxy_pass http://127.0.0.1:57860;
|
| 578 |
-
proxy_set_header Host $host;
|
| 579 |
-
proxy_set_header X-Real-IP $remote_addr;
|
| 580 |
-
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
| 581 |
-
proxy_set_header X-Forwarded-Proto $scheme;
|
| 582 |
-
|
| 583 |
-
# 处理 CORS
|
| 584 |
-
add_header Access-Control-Allow-Origin * always;
|
| 585 |
-
add_header Access-Control-Allow-Methods "GET, POST, PUT, DELETE, PATCH, OPTIONS" always;
|
| 586 |
-
add_header Access-Control-Allow-Headers "Content-Type, Authorization, X-Requested-With" always;
|
| 587 |
-
add_header Access-Control-Expose-Headers "Content-Type, Content-Length" always;
|
| 588 |
-
|
| 589 |
-
# 支持流式响应和 SSE
|
| 590 |
-
proxy_buffering off;
|
| 591 |
-
proxy_cache off;
|
| 592 |
-
proxy_set_header Connection '';
|
| 593 |
-
proxy_http_version 1.1;
|
| 594 |
-
chunked_transfer_encoding on;
|
| 595 |
-
|
| 596 |
-
# 超时设置
|
| 597 |
-
proxy_connect_timeout 60s;
|
| 598 |
-
proxy_send_timeout 300s;
|
| 599 |
-
}
|
| 600 |
-
|
| 601 |
-
location /log {
|
| 602 |
-
proxy_pass http://127.0.0.1:57860;
|
| 603 |
-
proxy_set_header Host $host;
|
| 604 |
-
proxy_set_header X-Real-IP $remote_addr;
|
| 605 |
-
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
| 606 |
-
proxy_set_header X-Forwarded-Proto $scheme;
|
| 607 |
-
|
| 608 |
-
# 处理 CORS
|
| 609 |
-
add_header Access-Control-Allow-Origin * always;
|
| 610 |
-
add_header Access-Control-Allow-Methods "GET, POST, PUT, DELETE, PATCH, OPTIONS" always;
|
| 611 |
-
add_header Access-Control-Allow-Headers "Content-Type, Authorization, X-Requested-With" always;
|
| 612 |
-
add_header Access-Control-Expose-Headers "Content-Type, Content-Length" always;
|
| 613 |
-
|
| 614 |
-
# 支持流式响应和 SSE
|
| 615 |
-
proxy_buffering off;
|
| 616 |
-
proxy_cache off;
|
| 617 |
-
proxy_set_header Connection '';
|
| 618 |
-
proxy_http_version 1.1;
|
| 619 |
-
chunked_transfer_encoding on;
|
| 620 |
-
|
| 621 |
-
# 超时设置
|
| 622 |
-
proxy_connect_timeout 60s;
|
| 623 |
-
proxy_send_timeout 300s;
|
| 624 |
-
}
|
| 625 |
-
|
| 626 |
-
location /tui {
|
| 627 |
-
proxy_pass http://127.0.0.1:57860;
|
| 628 |
-
proxy_set_header Host $host;
|
| 629 |
-
proxy_set_header X-Real-IP $remote_addr;
|
| 630 |
-
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
| 631 |
-
proxy_set_header X-Forwarded-Proto $scheme;
|
| 632 |
-
|
| 633 |
-
# 处理 CORS
|
| 634 |
-
add_header Access-Control-Allow-Origin * always;
|
| 635 |
-
add_header Access-Control-Allow-Methods "GET, POST, PUT, DELETE, PATCH, OPTIONS" always;
|
| 636 |
-
add_header Access-Control-Allow-Headers "Content-Type, Authorization, X-Requested-With" always;
|
| 637 |
-
add_header Access-Control-Expose-Headers "Content-Type, Content-Length" always;
|
| 638 |
-
|
| 639 |
-
# 支持流式响应和 SSE
|
| 640 |
-
proxy_buffering off;
|
| 641 |
-
proxy_cache off;
|
| 642 |
-
proxy_set_header Connection '';
|
| 643 |
-
proxy_http_version 1.1;
|
| 644 |
-
chunked_transfer_encoding on;
|
| 645 |
-
|
| 646 |
-
# 超时设置
|
| 647 |
-
proxy_connect_timeout 60s;
|
| 648 |
-
proxy_send_timeout 300s;
|
| 649 |
-
}
|
| 650 |
-
|
| 651 |
-
# OpenCode 根路径重定向
|
| 652 |
-
location = /opencode {
|
| 653 |
-
return 301 /opencode/;
|
| 654 |
-
}
|
| 655 |
-
|
| 656 |
-
# OpenCode API 代理 - 完整代理所有 OpenCode 端点 (v2)
|
| 657 |
-
location /opencode/ {
|
| 658 |
-
# 移除 /opencode 前缀
|
| 659 |
-
rewrite ^/opencode/(.*) /$1 break;
|
| 660 |
-
|
| 661 |
-
# 代理到 OpenCode 服务器
|
| 662 |
-
proxy_pass http://127.0.0.1:57860;
|
| 663 |
-
proxy_set_header Host $host;
|
| 664 |
-
proxy_set_header X-Real-IP $remote_addr;
|
| 665 |
-
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
| 666 |
-
proxy_set_header X-Forwarded-Proto $scheme;
|
| 667 |
-
|
| 668 |
-
# 处理 CORS
|
| 669 |
-
add_header Access-Control-Allow-Origin * always;
|
| 670 |
-
add_header Access-Control-Allow-Methods "GET, POST, PUT, DELETE, PATCH, OPTIONS" always;
|
| 671 |
-
add_header Access-Control-Allow-Headers "Content-Type, Authorization, X-Requested-With" always;
|
| 672 |
-
add_header Access-Control-Expose-Headers "Content-Type, Content-Length" always;
|
| 673 |
-
|
| 674 |
-
# 支持流式响应和 SSE
|
| 675 |
-
proxy_buffering off;
|
| 676 |
-
proxy_cache off;
|
| 677 |
-
proxy_set_header Connection '';
|
| 678 |
-
proxy_http_version 1.1;
|
| 679 |
-
chunked_transfer_encoding on;
|
| 680 |
-
|
| 681 |
-
# 超时设置
|
| 682 |
-
proxy_connect_timeout 60s;
|
| 683 |
-
proxy_send_timeout 300s;
|
| 684 |
}
|
| 685 |
|
| 686 |
error_page 500 502 503 504 /50x.html;
|
|
|
|
| 5 |
# 在Hugging Face Spaces环境中,重定向时不包含端口号
|
| 6 |
absolute_redirect off;
|
| 7 |
|
| 8 |
+
# 定义认证区域
|
| 9 |
+
auth_basic "Restricted Area";
|
| 10 |
+
auth_basic_user_file /usr/local/openresty/nginx/conf/.htpasswd;
|
|
|
|
| 11 |
|
| 12 |
+
# 使用 Lua 进行更复杂的认证
|
| 13 |
+
access_by_lua_block {
|
| 14 |
+
local headers = ngx.req.get_headers()
|
| 15 |
+
local user_agent = headers["User-Agent"] or ""
|
| 16 |
+
|
| 17 |
+
-- 简单的用户代理检查
|
| 18 |
+
if string.find(user_agent, "bot") then
|
| 19 |
+
ngx.exit(403)
|
| 20 |
+
end
|
| 21 |
+
}
|
| 22 |
|
| 23 |
+
# 默认站点 - nginx主页
|
| 24 |
+
location / {
|
| 25 |
root /usr/local/openresty/nginx/html;
|
| 26 |
index index.html index.htm;
|
| 27 |
|
|
|
|
| 36 |
add_header Content-Type text/plain;
|
| 37 |
}
|
| 38 |
|
| 39 |
+
# OpenCode Web 端点 - 统一代理所有web请求
|
| 40 |
+
location /opencode/web/ {
|
| 41 |
+
# 移除 /opencode/web 前缀
|
| 42 |
+
rewrite ^/opencode/web/(.*) /$1 break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
+
# 代理到 OpenCode 服务器
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
proxy_pass http://127.0.0.1:57860;
|
| 46 |
proxy_set_header Host $host;
|
| 47 |
proxy_set_header X-Real-IP $remote_addr;
|
|
|
|
| 65 |
proxy_connect_timeout 60s;
|
| 66 |
proxy_send_timeout 300s;
|
| 67 |
}
|
| 68 |
+
|
| 69 |
+
# OpenCode API 端点 - 统一代理所有API请求
|
| 70 |
+
location /opencode/api/ {
|
| 71 |
+
# 移除 /opencode/api 前缀
|
| 72 |
+
rewrite ^/opencode/api/(.*) /$1 break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
|
| 74 |
+
# 代理到 OpenCode 服务器
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
proxy_pass http://127.0.0.1:57860;
|
| 76 |
proxy_set_header Host $host;
|
| 77 |
proxy_set_header X-Real-IP $remote_addr;
|
|
|
|
| 95 |
proxy_connect_timeout 60s;
|
| 96 |
proxy_send_timeout 300s;
|
| 97 |
}
|
| 98 |
+
|
| 99 |
+
# OpenCode 静态资源代理 - 处理CSS、JS和其他资源
|
| 100 |
+
location /assets/ {
|
| 101 |
proxy_pass http://127.0.0.1:57860;
|
| 102 |
proxy_set_header Host $host;
|
| 103 |
proxy_set_header X-Real-IP $remote_addr;
|
| 104 |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
| 105 |
proxy_set_header X-Forwarded-Proto $scheme;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
}
|
| 107 |
|
| 108 |
+
location /oc-theme-preload.js {
|
| 109 |
proxy_pass http://127.0.0.1:57860;
|
| 110 |
proxy_set_header Host $host;
|
| 111 |
proxy_set_header X-Real-IP $remote_addr;
|
| 112 |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
| 113 |
proxy_set_header X-Forwarded-Proto $scheme;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
}
|
| 115 |
|
| 116 |
+
location /site.webmanifest {
|
| 117 |
proxy_pass http://127.0.0.1:57860;
|
| 118 |
proxy_set_header Host $host;
|
| 119 |
proxy_set_header X-Real-IP $remote_addr;
|
| 120 |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
| 121 |
proxy_set_header X-Forwarded-Proto $scheme;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
}
|
| 123 |
|
| 124 |
+
# OpenCode favicon 和图标资源
|
| 125 |
+
location ~ ^/(favicon.*\.(png|svg|ico)|apple-touch-icon\.png)$ {
|
| 126 |
proxy_pass http://127.0.0.1:57860;
|
| 127 |
proxy_set_header Host $host;
|
| 128 |
proxy_set_header X-Real-IP $remote_addr;
|
| 129 |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
| 130 |
proxy_set_header X-Forwarded-Proto $scheme;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 131 |
}
|
| 132 |
+
|
| 133 |
+
# OpenCode 根路径重定向到web端点
|
| 134 |
+
location = /opencode {
|
| 135 |
+
return 301 /opencode/web/;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 136 |
}
|
| 137 |
|
| 138 |
+
location = /opencode/ {
|
| 139 |
+
return 301 /opencode/web/;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 140 |
}
|
| 141 |
|
| 142 |
error_page 500 502 503 504 /50x.html;
|
test-nginx-config.sh
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
|
| 3 |
+
echo "=== 测试新的nginx配置 ==="
|
| 4 |
+
|
| 5 |
+
echo "1. 检查配置文件语法..."
|
| 6 |
+
# 简单检查配置文件语法
|
| 7 |
+
if [ -f "nginx/nginx.conf" ] && [ -f "nginx/conf.d/default.conf" ]; then
|
| 8 |
+
echo "✅ 配置文件存在"
|
| 9 |
+
else
|
| 10 |
+
echo "❌ 配置文件缺失"
|
| 11 |
+
exit 1
|
| 12 |
+
fi
|
| 13 |
+
|
| 14 |
+
echo "2. 验证端点配置..."
|
| 15 |
+
# 检查关键端点配置
|
| 16 |
+
echo "检查 /opencode/web/ 端点配置..."
|
| 17 |
+
if grep -q "location /opencode/web/" nginx/conf.d/default.conf; then
|
| 18 |
+
echo "✅ /opencode/web/ 端点已配置"
|
| 19 |
+
else
|
| 20 |
+
echo "❌ /opencode/web/ 端点未找到"
|
| 21 |
+
fi
|
| 22 |
+
|
| 23 |
+
echo "检查 /opencode/api/ 端点配置..."
|
| 24 |
+
if grep -q "location /opencode/api/" nginx/conf.d/default.conf; then
|
| 25 |
+
echo "✅ /opencode/api/ 端点已配置"
|
| 26 |
+
else
|
| 27 |
+
echo "❌ /opencode/api/ 端点未找到"
|
| 28 |
+
fi
|
| 29 |
+
|
| 30 |
+
echo "3. 验证认证配置..."
|
| 31 |
+
# 检查认证配置
|
| 32 |
+
if grep -q "auth_basic" nginx/conf.d/default.conf; then
|
| 33 |
+
echo "✅ HTTP Basic Auth已配置"
|
| 34 |
+
else
|
| 35 |
+
echo "❌ HTTP Basic Auth未找到"
|
| 36 |
+
fi
|
| 37 |
+
|
| 38 |
+
echo "4. 检查代理简化..."
|
| 39 |
+
# 统计代理端点数量
|
| 40 |
+
proxy_count=$(grep -c "proxy_pass http://127.0.0.1:57860" nginx/conf.d/default.conf)
|
| 41 |
+
echo "当前代理端点数量: $proxy_count"
|
| 42 |
+
|
| 43 |
+
echo "5. 验证重定向配置..."
|
| 44 |
+
if grep -q "location = /opencode" nginx/conf.d/default.conf; then
|
| 45 |
+
echo "✅ /opencode 重定向已配置"
|
| 46 |
+
else
|
| 47 |
+
echo "❌ /opencode 重定向未找到"
|
| 48 |
+
fi
|
| 49 |
+
|
| 50 |
+
echo ""
|
| 51 |
+
echo "=== 配置总结 ==="
|
| 52 |
+
echo "✅ 默认站点: nginx (根路径 /)"
|
| 53 |
+
echo "✅ OpenCode Web端点: /opencode/web/"
|
| 54 |
+
echo "✅ OpenCode API端点: /opencode/api/"
|
| 55 |
+
echo "✅ 统一认证: server级别Basic Auth"
|
| 56 |
+
echo "✅ 简化代理: 使用统一端点转发"
|
| 57 |
+
echo ""
|
| 58 |
+
echo "=== 访问方式 ==="
|
| 59 |
+
echo "主页: http://localhost:7860/ (需要认证)"
|
| 60 |
+
echo "OpenCode Web: http://localhost:7860/opencode/web/ (需要认证)"
|
| 61 |
+
echo "OpenCode API: http://localhost:7860/opencode/api/ (需要认证)"
|
| 62 |
+
echo "健康检查: http://localhost:7860/health (需要认证)"
|