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

添加SSL证书配置后无法重新启动Nginx?,ssl,nginx,Ssl,Nginx,我刚从Name.com购买了RapidSSL,并尝试按照此链接安装它 所以当我跑的时候 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/sit

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

所以当我跑的时候

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

有人知道怎么解决这个问题吗


谢谢

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

我能想到的两件事是: 1.错误的文件权限或错误的位置
2.错误的.crt内容-确保您的证书文件包含组合的证书+CA中间证书,顺序正确(证书优先,CA后)粘贴这些内容时,没有添加额外的行或缺少一些字符。

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

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

nginx:[emerg]BIO_new_文件(“/etc/nginx/~/key/www.mydomain.co.chained.crt”)失败(SSL:error:0201002:system library:fopen:No-this文件或目录:fopen('/etc/nginx/~/key/www.mydomain.co.chained.crt','r')错误:2006D080:BIO例程:BIO_new_文件:No-this文件)