NGINX 上的 SSL 证书无法加载

标签 ssl nginx

我正在尝试将从 Godaddy 获得的 SSL 证书安装到我的 NGINX 服务器上。我很肯定我的所有路径都是正确的,并且据我所知我的服务器配置是正确的,但我仍然收到以下错误。

Feb 20 11:06:35 my.server.com nginx[6173]: nginx: [emerg] cannot load certificate "/etc/ssl/certs/certificate.crt": BIO_new_file() failed (SSL: error:0200100D:system library:fopen:Permission denied:fopen('/etc/ssl/certs/certificate.crt','r') error:2006D002:BIO routines:BIO_new_file:system lib)
Feb 20 11:00:01 my.server.com nginx[5969]: nginx: configuration file /etc/nginx/nginx.conf test failed

下面是我的 SSL 配置。我已将其放入路径 /etc/nginx/conf.d/ssl.conf 的文件中.
server {
    listen       443 ssl http2 default_server;
        listen       [::]:443 ssl http2 default_server;
        server_name  my.server.com;
        root         /usr/share/nginx/html;

        ssl_certificate /etc/ssl/certs/certificate.crt;
        ssl_certificate_key /etc/ssl/private/private.key;
        ssl_session_cache shared:SSL:1m;
        ssl_session_timeout  10m;
        ssl_ciphers HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers on;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        location / {
               proxy_pass http://[MY_IP_ADDRESS]:8443;
               proxy_http_version 1.1;
               proxy_set_header Upgrade $http_upgrade;
               proxy_set_header Connection 'upgrade';
               proxy_set_header Host $host;
               proxy_cache_bypass $http_upgrade;
        }

        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
    }
}

这看起来是一个权限问题,但我已经运行 chown 将权限更改为 root 用户,并且我已通过 chmod 将文件权限更改为 600。这不正确吗?有人可以给我一些关于如何解决这个问题的指导吗?

** 更新 **

我确实检查并发现 SSL 证书不属于 root 用户。我已将所有 SSL 文件修改为由 root 所有者和组拥有,并将文件权限更改为 600,我尝试了 700。当我运行 sudo ls -l 时,我得到以下输出
-rwx------. 1 root root 7072 Feb 20 10:41 my.server.com.chained.crt
-rwx------. 1 root root 2277 Feb 20 10:36 my.server.com.crt
-rwx------. 1 root root 4795 Feb 20 10:39 intermediate.crt

我仍然遇到同样的错误。我也尝试过普通证书和全链证书。有谁知道发生了什么?

最佳答案

我终于解决了我的问题。结果当我移动文件(mv)时,它改变了文件的安全上下文,从而使它们对 nginx 不可读。我通过在我的根 nginx 文件夹上运行以下命令解决了这个问题。

restorecon -v -R /etc/nginx

我从这个 post 中找到了这个.

感谢所有的帮助!

关于NGINX 上的 SSL 证书无法加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60318580/

相关文章:

WCF 2-way ssl 不工作

ssl - Rancher - 对 ingress.local 有效

java - SSLHandshakeErrorTracker : SSLC0008E: Unable to initialize SSL connection. 未经授权的访问被拒绝或安全设置已过期

nginx - Vagrant - centos 网络

ssl - 400 错误请求 : The SSL certificate error

rest - 本地/云 REST 应用程序的安全性

asp.net - 集成 Windows 身份验证和 SSL

nginx proxy_pass和URL解码

ruby - 修复 OS X 上 Phusion Passenger + Sinatra +Nginx 的权限错误

nginx - 使用 NGINX 1.25 在多个域上启用 QUIC/http/3