Skip to main content

CentOS Nginx Proxy for OpenAI Error host not found in upstream "api.openai.com"

centos上用nginx搭建openai的反向代理服务器,始终报如下错误,但是我另外一台服务器上同样的nginx配置就是没问题的,真的恼人,2个小时的研究,终于找到了问题所在。

果然操作系统层面的问题,centos,竟然SELinux settings导致的问题,修改相关参数。再重启就没有问题了。

错误信息如下:

nginx: [emerg] host not found in upstream "api.openai.com" in /etc/nginx/nginx.conf:57 

解决办法

检查SElinux的参数配置

It will display the current SELinux mode, such as "Enforcing," "Permissive," or "Disabled."

[root@servername nginx]# sestatus

SELinux status:                 enabled

SELinuxfs mount:                /sys/fs/selinux

SELinux root directory:         /etc/selinux

Loaded policy name:             targeted

Current mode:                   enforcing

Mode from config file:          enforcing

Policy MLS status:              enabled

Policy deny_unknown status:     allowed

Max kernel policy version:      31

[root@servername nginx]# sudo setenforce 0

[root@servername nginx]# sestatus

SELinux status:                 enabled

SELinuxfs mount:                /sys/fs/selinux

SELinux root directory:         /etc/selinux

Loaded policy name:             targeted

Current mode:                   permissive

Mode from config file:          enforcing

Policy MLS status:              enabled

Policy deny_unknown status:     allowed

Max kernel policy version:      31


2 重新修改SElinux的参数值

This mode allows SELinux to log potential policy violations without enforcing them. Run the following command:

sudo setenforce 0

然后重新启动nginx服务就正常了。

Comments