Spaces:
Building
Building
worker_processes auto; | |
error_log /var/log/nginx/error.log warn; | |
pid /var/run/nginx.pid; | |
events { | |
worker_connections 1024; | |
} | |
http { | |
include /etc/nginx/mime.types; | |
default_type application/octet-stream; | |
log_format main '$remote_addr - $remote_user [$time_local] "$request" ' | |
'$status $body_bytes_sent "$http_referer" ' | |
'"$http_user_agent" "$http_x_forwarded_for"'; | |
access_log /var/log/nginx/access.log main; | |
client_body_temp_path /var/cache/nginx/client_temp; | |
proxy_temp_path /var/cache/nginx/proxy_temp; | |
fastcgi_temp_path /var/cache/nginx/fastcgi_temp; | |
uwsgi_temp_path /var/cache/nginx/uwsgi_temp; | |
scgi_temp_path /var/cache/nginx/scgi_temp; | |
sendfile on; | |
keepalive_timeout 65; | |
# GZIP 压缩配置 | |
gzip on; | |
gzip_disable "msie6"; | |
gzip_vary on; | |
gzip_proxied any; | |
gzip_comp_level 6; | |
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript; | |
# 定义限速区域 | |
limit_req_zone $binary_remote_addr zone=api_limit:10m rate=10r/m; | |
# 更新 SSL 配置 | |
ssl_protocols TLSv1.2 TLSv1.3; | |
ssl_ciphers HIGH:!aNULL:!MD5; | |
# 优化 SSL 参数 | |
ssl_prefer_server_ciphers on; # 优先使用服务器的密码套件 | |
ssl_session_timeout 1d; # SSL 会话超时时间 | |
ssl_session_cache shared:SSL:50m; # SSL 会话缓存 | |
ssl_session_tickets off; # 禁用 session tickets | |
# 模拟 Chrome 的 ECDH 曲线 | |
ssl_ecdh_curve X25519:prime256v1:secp384r1; | |
# 添加上游服务器 SSL 验证配置 | |
proxy_ssl_protocols TLSv1.2 TLSv1.3; | |
proxy_ssl_ciphers HIGH:!aNULL:!MD5; | |
proxy_ssl_verify off; # 如果上游证书验证有问题,可以先关闭验证 | |
proxy_ssl_server_name on; # 启用 SNI 支持 | |
server { | |
listen 7860; | |
server_name localhost; | |
location / { | |
root /usr/share/nginx/html; | |
index index.html index.htm; | |
try_files $uri $uri/ /index.html; | |
} | |
# Gemini v1 路由 | |
location /gemini/v1/ { | |
# 启用限速 | |
limit_req zone=api_limit burst=20 nodelay; | |
limit_req_status 429; | |
proxy_pass https://generativelanguage.googleapis.com/v1/; | |
proxy_set_header Host generativelanguage.googleapis.com; | |
proxy_set_header X-Real-IP $remote_addr; | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
} | |
# Gemini v1beta 路由 | |
location /gemini/v1beta/ { | |
# 启用限速 | |
limit_req zone=api_limit burst=20 nodelay; | |
limit_req_status 429; | |
proxy_pass https://generativelanguage.googleapis.com/v1beta/; | |
proxy_set_header Host generativelanguage.googleapis.com; | |
proxy_set_header X-Real-IP $remote_addr; | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
} | |
# Groq OpenAI 路由 | |
location /groq/openai/v1/ { | |
# 启用限速 | |
limit_req zone=api_limit burst=20 nodelay; | |
limit_req_status 429; | |
proxy_pass https://api.groq.com/openai/v1/; | |
proxy_set_header Host api.groq.com; | |
proxy_set_header X-Real-IP $remote_addr; | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
} | |
# Cohere 路由 | |
location /cohere/v1/ { | |
# 启用限速 | |
limit_req zone=api_limit burst=20 nodelay; | |
limit_req_status 429; | |
proxy_pass https://api.cohere.ai/v1/; | |
proxy_set_header Host api.cohere.ai; | |
proxy_set_header X-Real-IP $remote_addr; | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
} | |
# XAI 路由 | |
location /xai/v1/ { | |
# 启用限速 | |
limit_req zone=api_limit burst=20 nodelay; | |
limit_req_status 429; | |
proxy_pass https://api.x.ai/v1/; | |
proxy_set_header Host api.x.ai; | |
proxy_set_header X-Real-IP $remote_addr; | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
} | |
# Mistral 路由 | |
location /mistral/v1/ { | |
# 启用限速 | |
limit_req zone=api_limit burst=20 nodelay; | |
limit_req_status 429; | |
proxy_pass https://api.mistral.ai/v1/; | |
proxy_set_header Host api.mistral.ai; | |
proxy_set_header X-Real-IP $remote_addr; | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
} | |
# GitHub 路由 | |
location /github/v1/ { | |
# 启用限速 | |
limit_req zone=api_limit burst=20 nodelay; | |
limit_req_status 429; | |
proxy_pass https://models.inference.ai.azure.com/; | |
proxy_set_header Host models.inference.ai.azure.com; | |
proxy_set_header X-Real-IP $remote_addr; | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
} | |
# 错误页面配置 | |
error_page 500 502 503 504 /50x.html; | |
location = /50x.html { | |
root /usr/share/nginx/html; | |
} | |
} | |
} | |