【问题标题】:How can I use "let's encrypt" without stopping nginx?如何在不停止 nginx 的情况下使用“让我们加密”?
【发布时间】:2017-08-03 01:48:14
【问题描述】:

我正在为我们的服务器添加https 支持。添加 Let's Encrypt 支持时如何不停止 Nginx?

【问题讨论】:

    标签: lets-encrypt certbot


    【解决方案1】:

    将此块添加到您的server 配置(取决于您的服务器配置,您可以使用/var/www/html 以外的其他路径):

    location ~ /.well-known {
        root /var/www/html;
        allow all;
    }
    

    重新加载nginx,运行certbot如下:

    certbot certonly -a webroot --webroot-path=/var/www/html -d yourdomain.example
    

    将生成的证书应用于您的 server 配置

    ssl_certificate /etc/letsencrypt/live/yourdomain.example/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/yourdomain.example/privkey.pem;
    

    确保服务器设置配置为使用 ssl 在端口 443 上运行:

    listen 443 ssl;
    

    重新加载 nginx。在重新加载之间,您可以通过运行nginx -t 来确保配置没有语法错误。

    【讨论】:

      【解决方案2】:

      您可以为此使用 docker。 Link on hub.docker

      例如:

      创建 certbot.sh

      为此,您必须在 CLI 中运行:

      touch certbot.sh && chmod +x ./certbot.sh
      

      写入文件:

      #!/usr/bin/env bash
      docker run --rm -v /etc/letsencrypt:/etc/letsencrypt -v /var/lib/letsencrypt:/var/lib/letsencrypt certbot/certbot "$@"
      

      然后像这样运行:

      ./certbot.sh --webroot -w /var/www/example -d example.com -d www.example.com -w /var/www/thing -d thing.is -d m.thing.is
      

      ./certbot.sh renew
      

      您可以在 crontab 中添加调用此方法进行更新

      0 0 1 * * /<PATH_TO_FILE>/certbot.sh renew
      

      【讨论】:

        【解决方案3】:

        针对所有答案,您可以在 nginx 模式下运行 certbot。
        只需阅读文档即可。
        您所要做的就是安装一个额外的 nginx 插件并遵循 certbot 的文档。
        该插件甚至会在更新后立即在 nginx ram 中热重新加载缓存的证书。

        https://certbot.eff.org/instructions

        或者转到 nginx 文档:https://www.nginx.com/blog/using-free-ssltls-certificates-from-lets-encrypt-with-nginx/

        【讨论】:

        猜你喜欢
        • 2018-04-12
        • 1970-01-01
        • 1970-01-01
        • 2021-06-02
        • 2013-09-22
        • 1970-01-01
        • 1970-01-01
        • 2016-11-21
        • 2018-08-30
        相关资源
        最近更新 更多