上文中讲到在服务器端为OpenAI设置了推流,使用户体验更丝滑。但还有一关,那就是Nginx的反向代理和https。服务器端只是用了nodejs来提供服务,但如果没有https的话,一般的网站也是用不的(现在的浏览器一般都不太支持http了),必须经Nginx走一遭,配置好https。
当我以为可以很轻松搞定的时候,Nginx又给我出了难题!访问倒是能访问,但是无法使用推流,还是仍然只能等待全部结果后一次返回!这不是又走回头路了么?早前干的活打了水漂?!
一番查找和折腾下,终于算是搞定了,饭都没怎么吃好,真心不易。
server {
server_name api.example.com;
location / {
proxy_pass http://127.0.0.1:6200; //openai streaming
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;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
listen 443 ssl so_keepalive=on; # managed by Certbot
ssl_certificate /etc/letsen/live/api.example.com/full.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/api.example.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl.pem; # managed by Certbot
}
主要是Nginx的几个配置,平时用的也不多,出问题了只能临时去查和调整。整好后,效果还不错,AI·Joe的反应时间和体验大大提升了。
HTTP is in use instead of HTTPS and no protocol redirection is in place. Do not enter sensitive information in this website as your data won't be encrypted.
Read about HTTP unsafety: [https://whynohttps.com](1) [https://web.dev/why-https-matters](2)
_ Vote for our WITNESS to support this FREE service!