本地测试,通过配置nginx.conf文件,实现访问指定ip+端口能够自动转发至千问的API,但实际情况通过阅读nginx日志,请求被强制转发至https的协议,实际期望是使用http。想请问如何解决nginx代理转发的问题。
``` server {
listen 8162;
server_name localhost;
location /compatible-mode/v1/chat/completions {
proxy_pass http://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Authorization "Bearer **";
proxy_set_header Content-Type "application/json";
}
当访问localhost:8162/compatible-mode/v1/chat/completions地址时,期望被转发到千问模型的API。但实际返回结果报错
```{
"error": {
"message": "You didn't provide an API key. You need to provide your API key in an Authorization header using Bearer auth (i.e. Authorization: Bearer YOUR_KEY). ",
"type": "invalid_request_error",
"param": null,
"code": null
},
"request_id": "dffc652a-ac69-9d18-9a64-037c20a18a8c"
}
nginx日志可以看到被永久重定向到https地址
```2025/01/22 14:53:49 [debug] 22244#24384: *1 HTTP/1.1 308 Permanent Redirect
Server: nginx/1.24.0
Date: Wed, 22 Jan 2025 06:53:49 GMT
Content-Length: 0
Connection: keep-alive
location: https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions
vary: Accept-Encoding
```
但本地使用postman直接调用http的阿里云地址是正常的。
想请问如何使用nginx来代理阿里云的大模型API。
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。