反向代理配置代码
点击查看代码
#PROXY-START/
location /
{
proxy_pass https://api.openai.com;
proxy_set_header Host $proxy_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_http_version 1.1;
proxy_ssl_server_name on;
# proxy_hide_header Upgrade;
add_header X-Cache $upstream_cache_status;
#Set Nginx Cache
if ( $uri ~* "\.(gif|png|jpg|css|js|woff|woff2)$" )
{
expires 1m;
}
proxy_ignore_headers Set-Cookie Cache-Control expires;
proxy_cache cache_one;
proxy_cache_key $host$uri$is_args$args;
proxy_cache_valid 200 304 301 302 1m;
}
#PROXY-END/
问题1:
502 bad Gateway
启用参数proxy_ssl_server_name on;
解决问题
详情可参考文章https://blog.csdn.net/liuxiao723846/article/details/127749786
问题2
403 foribdden
proxy_set_header Host $http_host;
要改成:
proxy_set_header Host $proxy_host;
解决问题。
详情与原理请参考文章https://www.cnblogs.com/windysai/p/16611389.html