添加SSL证书配置后无法重新启动Nginx?

时间:2016-12-14 19:19:06

标签: ssl nginx

我只是从Name.com购买RapidSSL,并尝试按照此链接安装它

https://www.digitalocean.com/community/tutorials/how-to-install-an-ssl-certificate-from-a-commercial-certificate-authority

所以当我跑

sudo service nginx restart

我明白了。

Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.

所以这是我的/etc/nginx/sites-available/default

server {
    listen 80;
    server_name mydomain.co;
    rewrite ^/(.*) https://mydomain.co/$1 permanent;
}

server { 
    listen 443 ssl;

    ssl_certificate ~/key/www.mydomain.co.chained.crt;
    ssl_certificate_key ~/key/www.mydomain.co.key;

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;
    ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';

    server_name mydomain.co;
    root /www/mydomain/build;
    index index.html index.htm;
    rewrite ^/(.*)/$ $1 permanent;

    location ~ ^.+\..+$ {
      try_files $uri =404;
    }   

    location / {
        try_files $uri $uri/ /index.html;
    }

    location ~ /\. {
        deny all;
        access_log off;
        log_not_found off;
        return 404;
    }
}

但是当我删除这一行

ssl_certificate ~/key/www.mydomain.co.chained.crt;

我可以重新启动nginx。

任何人都知道如何解决这个问题?

谢谢!

2 个答案:

答案 0 :(得分:1)

nginx配置文件中的~可能无法按预期方式工作。我假设您打算将其变为/home/username/key/www.mydomain.co.chained.crt,但它不会被这样处理。

要确认这一点,请阅读配置行,然后运行nginx -t。您将看到nginx的配置检查错误日志:

  

nginx:[emerg] BIO_new_file(" /etc/nginx/~/key/www.mydomain.co.chained.crt")失败(SSL:错误:02001002:系统库:fopen:否这样的文件或目录:fopen(' /etc/nginx/~/key/www.mydomain.co.chained.crt',' r')错误:2006D080:BIO例程:BIO_new_file :没有这样的文件)

答案 1 :(得分:0)

由于我的新用户信誉,我无法发表评论,但你介意粘贴nginx错误日志吗?失败的原因应该在那里

我能想到的两件事是: 1.错误的文件权限或错误的位置 2.错误的.c​​rt内容 - 确保您的证书文件包含正确顺序的组合证书+ CA中间证书(证书优先,CA之后)以及粘贴未添加额外行或错过某些字符的那些证书。

相关问题