-
Notifications
You must be signed in to change notification settings - Fork 433
/
nginx.conf
94 lines (80 loc) · 2.89 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
server {
listen 80;
# 这里配置服务器的域名
#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;
}
# 如果你在同一台服务器上部署了 AIdea 前端项目,这里指定前端项目的路径
# 注意不要忘记注释掉上面的默认禁止直接访问 API 根地址的配置
# location / {
# root /data/app;
# index index.html;
# try_files $uri $uri/ =404;
# }
# 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 'upgrade';
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;
}
# Universal Link
location /.well-known/apple-app-site-association {
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;
#}