certbot 自动配置 HTTPS 证书时,指定 nginx 配置文件路径

文章目录

    今天在一台 CentOS 7.3 的服务器上配置新网站域名的 HTTPS 证书,Web Server 用的 Nginx。

    certbot 提示 nginx.conf 文件找不到。

    # certbot --nginx
    Saving debug log to /var/log/letsencrypt/letsencrypt.log
    Error while running nginx -c /etc/nginx/nginx.conf -t.
    
    nginx: [emerg] open() "/etc/nginx/nginx.conf" failed (2: No such file or directory)
    nginx: configuration file /etc/nginx/nginx.conf test failed
    

    但是这台服务器是用的某 panel 安装的 Nginx,所以 nginx.conf 文件并不在默认的路径上。查了半天才找到自定义路径的方法:

    certbot --nginx --nginx-server-root=/some/other/path/nginx/conf
    

    unrecognized arguments: –nginx-server-root

    但是,今天,上面问题第一次遇到的4年后,我又遇到了一个更加奇葩的报错

    sudo certbot --nginx --nginx-server-root=/www/server/nginx/conf
    

    certbot: error: unrecognized arguments: –nginx-server-root /www/server/nginx/conf

    Google 不到解决方案,又尝试命令:

    $ sudo certbot --nginx
    
    Saving debug log to /var/log/letsencrypt/letsencrypt.log
    The requested nginx plugin does not appear to be installed
    

    解决方案:

    sudo yum install python-certbot-nginx
    

    网上有的说是用 python3-certbot-nginx,但是我这台安装 certbot 时,我留意了一下是以 python2 安装的。所以这里没有加 python3。

    最后

    我在 Ubuntu 上从来没有遇到过这么多奇葩的问题。感觉用 CentOS 完全是跟自己过不去哇。

    关于作者 🌱

    我是来自山东烟台的一名开发者,有感兴趣的话题,或者软件开发需求,欢迎加微信 zhongwei 聊聊,或者关注我的个人公众号“大象工具”, 查看更多联系方式