CoolFace
Apppublic

ZSCGR/nginx-proxy

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes
nginx.conf160 linesDownload Raw Back to root
1worker_processes  auto;2 3error_log  /var/log/nginx/error.log warn;4pid /var/run/nginx.pid;5 6events {7    worker_connections  1024;8}9 10http {11    include       /etc/nginx/mime.types;12    default_type  application/octet-stream;13 14    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '15                      '$status $body_bytes_sent "$http_referer" '16                      '"$http_user_agent" "$http_x_forwarded_for"';17 18    access_log  /var/log/nginx/access.log  main;19 20    client_body_temp_path /var/cache/nginx/client_temp;21    proxy_temp_path       /var/cache/nginx/proxy_temp;22    fastcgi_temp_path    /var/cache/nginx/fastcgi_temp;23    uwsgi_temp_path      /var/cache/nginx/uwsgi_temp;24    scgi_temp_path       /var/cache/nginx/scgi_temp;25 26    sendfile        on;27    keepalive_timeout  65;28 29    # GZIP 压缩配置30    gzip on;31    gzip_disable "msie6";32    gzip_vary on;33    gzip_proxied any;34    gzip_comp_level 6;35    gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;36    37    # 定义限速区域38    limit_req_zone $binary_remote_addr zone=api_limit:10m rate=10r/m;39 40    # 更新 SSL 配置41    ssl_protocols TLSv1.2 TLSv1.3;42    ssl_ciphers HIGH:!aNULL:!MD5;43 44    # 优化 SSL 参数45    ssl_prefer_server_ciphers on;  # 优先使用服务器的密码套件46    ssl_session_timeout 1d;        # SSL 会话超时时间47    ssl_session_cache shared:SSL:50m;  # SSL 会话缓存48    ssl_session_tickets off;       # 禁用 session tickets49 50    # 模拟 Chrome 的 ECDH 曲线 51    ssl_ecdh_curve X25519:prime256v1:secp384r1;52 53    # 添加上游服务器 SSL 验证配置54    proxy_ssl_protocols TLSv1.2 TLSv1.3;55    proxy_ssl_ciphers HIGH:!aNULL:!MD5;56    proxy_ssl_verify off;  # 如果上游证书验证有问题,可以先关闭验证57    proxy_ssl_server_name on;  # 启用 SNI 支持58 59    server {60        listen       7860;61        server_name  localhost;62 63        location / {64            root   /usr/share/nginx/html;65            index  index.html index.htm;66            try_files $uri $uri/ /index.html;67        }68        # Gemini v1 路由69        location /gemini/v1/ {70            # 启用限速71            limit_req zone=api_limit burst=20 nodelay;72            limit_req_status 429;73 74            proxy_pass https://generativelanguage.googleapis.com/v1/;75            proxy_set_header Host generativelanguage.googleapis.com;76            proxy_set_header X-Real-IP $remote_addr;77            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;78        }79 80        # Gemini v1beta 路由81        location /gemini/v1beta/ {82            # 启用限速83            limit_req zone=api_limit burst=20 nodelay;84            limit_req_status 429;85 86            proxy_pass https://generativelanguage.googleapis.com/v1beta/;87            proxy_set_header Host generativelanguage.googleapis.com;88            proxy_set_header X-Real-IP $remote_addr;89            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;90        }91 92        # Groq OpenAI 路由93        location /groq/openai/v1/ {94            # 启用限速95            limit_req zone=api_limit burst=20 nodelay;96            limit_req_status 429;97 98            proxy_pass https://api.groq.com/openai/v1/;99            proxy_set_header Host api.groq.com;100            proxy_set_header X-Real-IP $remote_addr;101            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;102        }103 104        # Cohere 路由105        location /cohere/v1/ {106            # 启用限速107            limit_req zone=api_limit burst=20 nodelay;108            limit_req_status 429;109 110            proxy_pass https://api.cohere.ai/v1/;111            proxy_set_header Host api.cohere.ai;112            proxy_set_header X-Real-IP $remote_addr;113            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;114        }115 116        # XAI 路由117        location /xai/v1/ {118            # 启用限速119            limit_req zone=api_limit burst=20 nodelay;120            limit_req_status 429;121 122            proxy_pass https://api.x.ai/v1/;123            proxy_set_header Host api.x.ai;124            proxy_set_header X-Real-IP $remote_addr;125            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;126        }127 128        # Mistral 路由129        location /mistral/v1/ {130            # 启用限速131            limit_req zone=api_limit burst=20 nodelay;132            limit_req_status 429;133 134            proxy_pass https://api.mistral.ai/v1/;135            proxy_set_header Host api.mistral.ai;136            proxy_set_header X-Real-IP $remote_addr;137            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;138        }139 140        # GitHub 路由141        location /github/v1/ {142            # 启用限速143            limit_req zone=api_limit burst=20 nodelay;144            limit_req_status 429;145 146            proxy_pass https://models.inference.ai.azure.com/;147            proxy_set_header Host models.inference.ai.azure.com;148            proxy_set_header X-Real-IP $remote_addr;149            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;150        }151 152        # 错误页面配置153        error_page   500 502 503 504  /50x.html;154        location = /50x.html {155            root   /usr/share/nginx/html;156        }157    }158}159 160