ssl - 添加SSL证书配置后无法重启Nginx?

标签 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。

有人知道如何解决这个问题吗?

谢谢!

最佳答案

您的 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") failed (SSL: error:02001002:system library:fopen:No such file or directory:fopen('/etc/nginx/~/key/www.mydomain.co.chained.crt','r') error:2006D080:BIO routines:BIO_new_file:no such file)

关于ssl - 添加SSL证书配置后无法重启Nginx?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41150486/

相关文章:

nginx - nginx 可以对 websocket 连接进行透明压缩吗?

node.js - 如何在 Nginx Docker 镜像上使用 Traefik PathPrefix?

node.js - 将没有端口号的域名链接到 nginx 托管的 MEAN stack 服务器

wordpress - 我网站的 https 被划掉了

ssl - 尝试将 Paypal 证书更改集成到 GoDaddy 共享托管环境中时出现问题

linux - 使用运行 Apache 的 Ubuntu 服务器的 godaddy SSL

apache - FQDN 上的 SSL 与 IP

php - 下载 PDF - 失败 : Network error, PHP-FPM 和 Nginx

java - 带有 tomcat 服务器的自签名证书的 TLS - 无法加载 PEM 客户端证书

ssl - 让 EV SSL 证书在 Nginx 上工作的问题