LINUX 서버 의 가장 간결 한 HTTPS 무료 인증서 설정 방법
3342 단어 [Linux 와 Shell]
: https , ; , , , , ,
、 https , 443
① root , : ,
wget https://dl.eff.org/certbot-auto
② nginx, , 80
service nginx stop
③
// [email protected] ,
// www.xieyouhui.com https , -d
./certbot-auto certonly --standalone --email [email protected] --agree-tos -d www.xieyouhui.com -d app.xieyouhui.com -d admin.xieyouhui.com
//
./certbot-auto certonly --standalone --email [email protected] --agree-tos -d www.weimi888.com -d weimi888.com
./certbot-auto: Permission denied , certbot-auto
④
ls /etc/letsencrypt/live/
⑤ nginx
//
ssl_certificate /etc/letsencrypt/live/cdw.me/fullchain.pem;#
ssl_certificate_key /etc/letsencrypt/live/cdw.me/privkey.pem;#
⑥ nginx
service nginx start
https
2、 , , ③ ,
service nginx stop nginx
./certbot-auto renew -v ,certbot-auto
service nginx start nginx
3、 certbot-auto , :
// , ,
./certbot-auto renew --quiet --no-self-upgrade
: ,
# 1 5 , nginx
00 05 01 * * /root/certbot renew --quiet && /bin/systemctl restart nginx
# SSL
30 2 3 * * /root/letsencrypt/./letsencrypt-auto renew > /var/log/le-renew.log && nginx -s reload
、 , ,
https://liuniu.oss-cn-zhangjiakou.aliyuncs.com/xyh/peizhiwenjian.zip
、
/**
* SSL
* param $domain , www.baidu.com
* return array
*/
public function getValidity($domain){
$context = stream_context_create(array("ssl" => array("capture_peer_cert_chain" => true)));
$socket = stream_socket_client("ssl://$domain:443", $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $context);
$context = stream_context_get_params($socket);
foreach ($context["options"]["ssl"]["peer_certificate_chain"] as $value) {
// openssl , x509
$cerInfo = openssl_x509_parse($value);
if(strpos($cerInfo['name'],$domain)) {
//
$early_warning_time = time() - 3 * 24 * 3600;
if ($cerInfo['validTo_time_t'] <= $early_warning_time) {
$end_type = 1;
} else {
$end_type = 0;
}
$result = array(
'start_time' => date("Y-m-d H:i",$cerInfo['validFrom_time_t']), //
'end_time' => date("Y-m-d H:i",$cerInfo['validTo_time_t']), //
'end_type' => $end_type
);
return $result;
}
}
}