新建一个站点,申请证书,添加反向代理或者如下 ### 修改站点配置文件 ``` server { listen 443 ssl; server_name {your_domain_name}; ssl_certificate {your_cert_path}; ssl_certificate_key {your_cert_key_path}; ssl_session_cache shared:le_nginx_SSL:1m; ssl_session_timeout 1440m; ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; ssl_prefer_server_ciphers on; ssl_ciphers TLS13-AES-256-GCM-SHA384:TLS13-CHACHA20-POLY1305-SHA256:TLS13-AES-128-GCM-SHA256:TLS13-AES-128-CCM-8-SHA256:TLS13-AES-128-CCM-SHA256:EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+ECDSA+AES128:EECDH+aRSA+AES128:RSA+AES128:EECDH+ECDSA+AES256:EECDH+aRSA+AES256:RSA+AES256:EECDH+ECDSA+3DES:EECDH+aRSA+3DES:RSA+3DES:!MD5; location / { proxy_pass https://api.openai.com/; proxy_ssl_server_name on; proxy_set_header Host api.openai.com; proxy_set_header Connection ''; proxy_http_version 1.1; chunked_transfer_encoding off; proxy_buffering off; proxy_cache off; proxy_set_header X-Forwarded-For $remote_addr; proxy_set_header X-Forwarded-Proto $scheme; } } ``` 需要配置下 SSL 证书和你的域名 ### 测试聊天补全命令 ``` curl https://api.openai-proxy.com/v1/chat/completions \ -H "Content-Type: application/json" \ -H "Authorization: Bearer " \ -d '{ "model": "gpt-3.5-turbo", "messages": [{"role": "user", "content": "Hello!"}] }' ``` ### 响应结果 ``` { "id": "chatcmpl-21lvNzPaxlsQJh0BEIb9DqoO0pZUY", "object": "chat.completion", "created": 1680656905, "model": "gpt-3.5-turbo-0301", "usage": { "prompt_tokens": 10, "completion_tokens": 10, "total_tokens": 20 }, "choices": [ { "message": { "role": "assistant", "content": "Hello there! How can I assist you today?" }, "finish_reason": "stop", "index": 0 } ] } ```