nginx: [emerg] BIO_new_file(“E:\nginx-1.12.2/conf/cert.pem“) failed (SSL: error:02001002:system libr

本文详细介绍了在Nginx中配置SSL证书时遇到的常见错误:BIO_new_file失败,及其解决方法。通过注释掉配置文件中的HTTPS部分,可以避免因证书路径错误导致的启动失败问题。

nginx: [emerg] BIO_new_file(“E:\nginx-1.12.2/conf/cert.pem”) failed (SSL: error:02001002:system library:fopen:No such file or directory:fopen(‘E:\nginx-1.12.2/conf/cert.pem’,‘r’) error:2006D080:BIO routines:BIO_new_file:no such file)

解决方法 :

方法1 - 配置证书

方法2

# 将下面内容  全部注释即可,,此方法,仅本低测试过

	# HTTPS server
    #
    # server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    # }
Nginx 出现 `[emerg] cannot load certificate '/usr/local/nginx-1.24.0/conf/cert/_.wzhrss.gov.cn_chain.crt'` 以及 `BIO_new_file() failed` 错误,表明 Nginx 无法打开指定的证书文件,以下是可能的解决办法: ### 检查文件路径与权限 - **路径是否正确**:要保证 Nginx 配置文件里指定的证书文件路径准确无误,路径区分大小写。 ```nginx server { listen 443 ssl; server_name example.com; ssl_certificate /usr/local/nginx-1.24.0/conf/cert/_.wzhrss.gov.cn_chain.crt; ssl_certificate_key /path/to/your/private.key; # 其他配置... } ``` - **文件是否存在**:通过 `ls` 命令确认证书文件是否确实存在于指定路径。 ```bash ls /usr/local/nginx-1.24.0/conf/cert/_.wzhrss.gov.cn_chain.crt ``` - **文件权限**:Nginx 进程需要有读取证书文件的权限。可以使用 `chmod` 命令赋予文件合适的权限。 ```bash chmod 644 /usr/local/nginx-1.24.0/conf/cert/_.wzhrss.gov.cn_chain.crt ``` 同时,要确保 Nginx 进程所属的用户和组对包含证书文件的目录有访问权限。 ### 检查 SELinux 或 AppArmor - **SELinux**:如果系统启用了 SELinux,它可能会限制 Nginx 访问证书文件。可以临时禁用 SELinux 来测试是否是该原因导致的问题。 ```bash setenforce 0 ``` 若禁用后问题解决,可通过修改 SELinux 策略来允许 Nginx 访问证书文件。 ```bash semanage fcontext -a -t httpd_sys_content_t "/usr/local/nginx-1.24.0/conf/cert(/.*)?" restorecon -Rv /usr/local/nginx-1.24.0/conf/cert ``` - **AppArmor**:若系统使用 AppArmor,需要确保其配置允许 Nginx 访问证书文件。 ### 检查 Nginx 配置语法 在修改 Nginx 配置文件之后,要使用 `nginx -t` 命令检查配置文件的语法是否正确。 ```bash nginx -t ``` 若语法检查通过,再重新加载 Nginx 配置。 ```bash nginx -s reload ``` ### 检查文件损坏情况 可以使用文本编辑器打开证书文件,查看内容是否完整,有无乱码。若文件损坏,需要重新获取证书文件。
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值