forked from mylxsw/aidea-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nginx.conf
80 lines (68 loc) · 2.45 KB
/
nginx.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
server {
listen 443 ssl;
# 这里配置服务器的域名
server_name api.aidea.com;
gzip on;
gzip_static on;
gzip_vary on;
gzip_types text/plain application/x-javascript text/css application/xml text/xml application/javascript;
# 这里配置 SSL 证书路径
ssl_certificate /etc/nginx/certs.d/api.aidea.com.pem;
ssl_certificate_key /etc/nginx/certs.d/api.aidea.com.key;
# 将用户端的真实 IP 传递给后端服务
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
# 支持跨域(Web 端专用)
add_header Access-Control-Allow-Origin * always;
add_header Access-Control-Allow-Methods GET,OPTIONS,POST,PUT,DELETE always;
add_header Access-Control-Allow-Headers x-platform-version always;
add_header Access-Control-Allow-Headers x-client-version always;
add_header Access-Control-Allow-Headers x-platform always;
add_header Access-Control-Allow-Headers x-language always;
add_header Access-Control-Allow-Headers authorization always;
add_header Access-Control-Allow-Headers content-type always;
add_header Access-Control-Allow-Headers openai-organization always;
# 禁止直接访问 API 根地址
location / {
rewrite ^/(.*) http://127.0.0.1 redirect;
}
# OpenAI Chat Stream 协议支持(服务端推送)
location /v1/chat/completions {
proxy_pass http://ai_api_backend;
proxy_set_header Upgrade $http_upgrade;
proxy_http_version 1.1;
proxy_set_header Connection '';
chunked_transfer_encoding off;
proxy_cache off;
proxy_buffering off;
proxy_read_timeout 300s;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
# 公开 API v1
location /v1/ {
proxy_pass http://ai_api_backend;
}
# 公开 API v2
location /v2/ {
proxy_pass http://ai_api_backend;
}
# 公开 API
location /public/ {
proxy_pass http://ai_api_backend;
}
}
upstream ai_api_backend {
# 后端服务地址
server 192.168.0.109:8080;
keepalive 32;
}
# 所有 HTTP 请求重定向到 HTTPS
server {
listen 80;
# 这里配置服务器的域名
server_name api.aidea.com;
rewrite ^(.*) https://api.aidea.com$1 permanent;
}