Nginx: curl: (60) SSL证书问题:无法获取本地颁发者证书

3

我在docker中运行nginx并使用ssl,当我尝试使用url访问时,出现以下错误:

root@54a843786818:/# curl --location --request POST 'https://10.1.1.100/login' \
> --header 'Content-Type: application/json' \
> --data-raw '{
>     "username": "testuser",
>     "password": "testpassword"
> }'
curl: (60) SSL certificate problem: unable to get local issuer certificate
More details here: https://curl.haxx.se/docs/sslcerts.html

curl failed to verify the legitimacy of the server and therefore could not
establish a secure connection to it. To learn more about this situation and
how to fix it, please visit the web page mentioned above.

不检查证书选项时,它可以正常工作。

curl -k --location --request POST 'https://10.1.1.100/login' --header 'Content-Type: application/json' --data-raw '{
    "username": "testuser",
    "password": "testpassword"
}'
{"access_token": "xxxxxxxxxxxxxxxxxxxxxxxkkkkkkkkkkkkkkkkkkkk", "refresh_token": "qqqqqqqqqoooooooooxxxx"}

我的配置文件

root@54a843786818:/# cat /etc/nginx/sites-enabled/api.conf
server {
    listen 443 ssl;
    listen [::]:443 ssl;
    ssl_certificate /root/certs/my_hostname.my.domain.name.com.pem;
    ssl_certificate_key /root/certs/my_hostname.my.domain.name.com.key;

    location / {
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header HOST $http_host;
                proxy_pass http://10.1.1.100:5000;
                proxy_redirect off;
    }
}

我怀疑我的证书设置有问题。

以下是我遵循的确切步骤。

1) Taken private key and removed password using below commands

   # openssl rsa -in my_hostname.my.domain.name.com_password_ask.key -out my_hostname.my.domain.name.com.key

2) Converted .crt file .pem 
   # openssl x509 -in my_hostname.my.domain.name.com.crt -out my_hostname.my.domain.name.com.pem -outform PEM

3) Next copied .pem and .key and pasted under /root/certs on nginx docker container using cat and vim editor

4) Verified private keys  and public keys are matching below are the commands used 
  

root@54a843786818:~/certs# openssl rsa -noout -modulus -in my_hostname.my.domain.name.com.key | openssl md5
(stdin)= xcccxxxxxxxxxxxxxxxxxxxxxxxxxx
root@54a843786818:~/certs# openssl x509 -noout -modulus -in my_hostname.my.domain.name.com.pem | openssl md5
(stdin)= xcccxxxxxxxxxxxxxxxxxxxxxxxxxx

我单独获得了以下证书,不确定是否需要将它们捆绑在一起,如果需要,应该使用什么命令?
1) Certificate.pem
2) private_key
3) ca_intermediate_certificate.pem
4) ca_trusted_root

有人可以帮我解决问题吗?我不确定自己做错了什么,是否有办法验证我的证书,并检查它们能否提供 https 服务。

除了证书之外,是否有任何配置、设置等问题?


将servername添加到您的配置文件中,并在https://10.43.0.77/login中用my_hostname.my.domain.name.com/login替换IP。证书是针对域名而不是IP地址颁发的,因此当您使用IP访问https时会失败。 - Pavan Kumar T S
添加了主机名,但问题仍然存在。我有不同的证书,不确定是否要捆绑它们..也会更新问题。 - Vidya
我是指不要执行 curl -k --location --request POST 'https://10.43.0.77/login',而应该执行 curl -k --location --request POST 'https://my_hostname.my.domain.name.com/login'。 - Pavan Kumar T S
尝试添加DNS记录,将IP映射到域名。 - Pavan Kumar T S
这是您的本地系统。 - Pavan Kumar T S
显示剩余5条评论
1个回答

1

一个包括HTTPS在内的SSL/TLS服务器需要发送证书链,可选择性地排除根证书。假设您的文件名不是故意歪曲的,您有一个由3个证书(服务器、中间和根)组成的链,并且服务器必须至少发送实体证书和'ca_intermediate'证书;它可以包含也可以不包含'trusted_root'。 在nginx中,这是通过将证书串联到一个文件中来完成的;请参见概述文档,其中链接到特定指令ssl_certificate

此外,您服务器证书的根证书必须在客户端的信任存储中(如果有多个客户端,则每个客户端都需要)。如果该根证书是公共CA(如Digicert、GoDaddy、LetsEncrypt/ISRG)之一,则通常已经在大多数客户端的默认信任存储中,通常包括curl - 虽然curl的默认值可能因构建方式而异;运行curl -V(大写vee)以查看它使用哪个SSL/TLS实现。如果根证书是由您公司运行的CA,则公司的系统管理员通常会将其添加到公司系统上的信任存储中,但如果您正在使用他们不知道或未正确获取和管理的系统,则可能没有正确设置。如果您需要curl接受不在其默认信任存储中的根证书,请参阅手册页上的--cacert选项,无论是在Unixy系统上还是在网上。其他客户端不同,但您没有提到任何一个。

最后,如评论中所讨论的那样,在URL中使用的主机名必须与证书中指定的身份匹配,并且证书通常仅使用服务器的域名而不是IP地址进行发行。 (技术上可以为IP地址或多个IP地址颁发证书,但根据cabforum政策,如果公共CA为地址颁发证书,则不能为您这样的私有地址颁发证书- 10.0.0.0 / 8是RFC 1918中的一个私有范围。公司运行的CA可能会认证此类私有地址,也可能不会。)如果您的证书指定了域名,则必须将该名称或其中一个名称用作URL的主机部分;如果您没有设置DNS或主机文件以正确解析该域名以将其正确解析为主机地址,则可以使用curl选项 --resolve (也在man页面上)进行覆盖。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接