最近在使用 lnmp脚本工具包 的时候 里面的acme.sh脚本签发 Let's Encrypt证书报错

Please refer to https://curl.haxx.se/libcurl/c/libcurl-errors.html for error code: 28

根据网上搜索,说是参数换成强制wget就行了,经过测试发现一样不行,于是开始了折腾之路。

经过反复测试发现,在境外的主机上操作都是正常的,但是境内就不行,难道是网络缘故?

思来想去,还是把签发这个事放在境外吧。

于是新建一台境外实例,部署好lnmp,修改 php-fpm的配置文件 用户名和用户组都改成root (避免权限问题)然后 lnmp stop php-fpm

修改/etc/init.d/php-fpm 这个文件给php-fpm 添加一个启动参数

php_opts=" -R --allow-to-run-as-root  --fpm-config $php_fpm_CONF --pid $php_fpm_PID"

修改/usr/local/php/etc/php.ini 

在disable_functions 里面去掉exec

修改/usr/local/nginx/conf/fastcgi.conf

fastcgi_param PHP_ADMIN_VALUE "open_basedir=$document_root/:/tmp/:/proc/:/usr/local/nginx/conf/ssl/";

添加:/usr/local/nginx/conf/ssl/

准备工作就绪(lnmp php-fpm start && lnmp nginx reload),假设这台机器的域名是 ca.com 解析放在阿里云

在终端添加ssl虚拟主机,使用lnmp dns ali 然后根据lnmp的提示,添加好主机

再添加要帮忙签的域名,使用 lnmp onlyssl ali ,例如这里添加 abc.com

然后在/usr/local/nginx/conf/ssl/ 目录下可以找到对应域名的证书,我们只需要把文件复制到需要的服务器上就可以了,一般来说scp就行,但我采用了PHP更新的方案,所以这里要上代码了

服务端,也就是ca.com服务器上部署

<?php
if(empty($_POST['domain']) || !is_valid_domain_name($_POST['domain']))
{
    exit;
}
//获取域名的解析记录
$ip = dns_get_record($_POST['domain'],DNS_A);
if(isset($ip[0]) && isset($ip[0]['ip']))
{
    $ip = $ip[0]['ip'];
}else
{
    exit;
}
//判断访问来源和域名是否一致
if($ip !== $_SERVER['REMOTE_ADDR'])
{
    echo 3;
    exit;
}
//验证通过后开始打包证书文件
$base = '/usr/local/nginx/conf/ssl/';
$path = $base . $_POST['domain'] . '/';
if(file_exists($path))
{
    exec("cd '{$path}' && tar -czf {$_POST['domain']}.tgz ca.cer fullchain.cer {$_POST['domain']}.cer {$_POST['domain']}.csr {$_POST['domain']}.csr.conf {$_POST['domain']}.key");
    //计算hash
    $new_md5 = md5_file($path.$_POST['domain'].'.tgz');
    if($new_md5 !== $_POST['md5'])
    {
        send_file($path.$_POST['domain'].'.tgz');
    }
    echo 4;
}


//验证域名合法性
function is_valid_domain_name($domain_name)
{

    return(
        preg_match("/^([a-z\d](-*[a-z\d])*)(\.([a-z\d](-*[a-z\d])*))*$/i", $domain_name) //valid chars check

        && preg_match("/^.{1,253}$/", $domain_name) //overall length check

        && preg_match("/^[^\.]{1,63}(\.[^\.]{1,63})*$/", $domain_name) //length of each label
    );

}
//发送文件
function send_file($file) 
{
    $size = filesize($file); 
    header("Content-type: application/octet-stream"); 
    header("Accept-Ranges: bytes"); 
    $begin = 0; 
    $end = $size - 1; 
    header("Content-Length: " . ($end - $begin + 1)); 
    header("Content-Disposition: attachment;filename=".basename($file)); 
    header("Content-Range: bytes ".$begin."-".$end."/".$size); 
    echo file_get_contents($file); 
} 
ca.php

相关文章:

  • 2021-04-06
  • 2022-12-23
  • 2021-05-11
  • 2022-03-04
  • 2021-12-05
  • 2022-12-23
  • 2021-08-17
猜你喜欢
  • 2022-12-23
  • 2021-07-10
  • 2022-12-23
  • 2022-12-23
  • 2021-06-18
  • 2022-12-23
  • 2021-12-09
相关资源
相似解决方案