首页 » 网站建设 » 免费php支撑ssl技巧_运用Lets Encrypt 的Certbot 将您的网站免费生成https协议

免费php支撑ssl技巧_运用Lets Encrypt 的Certbot 将您的网站免费生成https协议

访客 2024-12-09 0

扫一扫用手机浏览

文章目录 [+]

yum install certbot 2、利用命令为域名天生签证 ;

  天生https签证:

certbot certonly --webroot -w /your_local_dir/wwwroot/yii2/frontend/web/ -d wechat.zsying.cn

  将https签证天生到制订文件夹中 --config-dir 参数

免费php支撑ssl技巧_运用Lets Encrypt 的Certbot 将您的网站免费生成https协议

certbot certonly --webroot -w /your_local_dir/wwwroot/yii2/frontend/web/ -d wechat.zsying.cn --config-dir /etc/nginx/conf.d/certss/把稳:

  your_local_dir : 是你的做事地址,请把稳项目路径。

免费php支撑ssl技巧_运用Lets Encrypt 的Certbot 将您的网站免费生成https协议
(图片来自网络侵删)
解释:

/your_local_dir/wwwroot/yii2/frontend/web/ : 网站的根目录;wechat.zsying.cn : 网站域名--config-dir /etc/nginx/conf.d/certss/ : http签证存储的地方缺点样例:

certbot certonly --webroot -w /your_local_dir/wwwroot/yii2/ -d wechat.zsying.cn --config-dir /etc/nginx/conf.d/certss/结果如图:

  缺点的地方便是 文件夹路径不是网站的根目录,

成功案例:

certbot certonly --webroot -w /your_local_dir/wwwroot/yii2/frontend/web/ -d wechat.zsying.cn --config-dir /etc/nginx/conf.d/certss/

结果如图:

  certbot供应很多的参数可以用,可参考这里 certbot 命令地址

  我们有其他例如nginx的做事,它占用了443端口,我们就要先停滞这些做事,在天生证书完毕后,我们再启用这些做事。

certbot certonly --standalone -d example.com -d www.example.com

  至此,我们的第一证诗人成已完成。
下一步是配置我们的Web做事器并启用HTTPS。

4 Nginx 配置启用 HTTPS

  我的配置是利用的是Nginx 做事器来转发要求,这里贴一下我的Nginx配置。

server { listen 80; server_name wechat.zsying.cn; rewrite ^(.) https://wechat.zsying.cn$1 permanent;}server { listen 443; server_name wechat.zsying.cn; access_log /your_local_dir/wwwlogs/wechat_access_nginx.log combined; error_log /your_local_dir/wwwlogs/error.log; root /your_local_dir/wwwroot/yii2/frontend/web; index index.html index.htm index.php; ssl_certificate /etc/nginx/conf.d/certss/live/wechat.zsying.cn/fullchain.pem; ssl_certificate_key /etc/nginx/conf.d/certss/live/wechat.zsying.cn/privkey.pem; #error_page 404 /404.html; #error_page 502 /502.html; location /nginx_status { stub_status on; access_log off; allow 127.0.0.1; deny all; } location ~ [^/]\.php(/|$) { #fastcgi_pass remote_php_ip:9000; fastcgi_pass unix:/dev/shm/php-cgi.sock; fastcgi_index index.php; fastcgi_split_path_info ^(.+\.php)(.)$; #增加这一句 fastcgi_param PATH_INFO $fastcgi_path_info; #增加这一句 include fastcgi.conf; } include maccms.conf; location ~ .\.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$ { expires 30d; access_log off; } location ~ .\.(js|css)?$ { expires 7d; access_log off; } location ~ ^/(\.user.ini|\.ht|\.git|\.svn|\.project|LICENSE|README.md) { deny all; } }

  配置紧张是监听 443 端口和启用 SSL,并配置了 SSL 的证书路径(公钥,私钥的路径),通过这些配置,我们就可以成功启用Https了。

  你打开网站的时候就可以看到标有 安全 的字样。
比如:

5 自动更新 SSL 证书

  配置完这些后,我们的事情尚未完成。
  Let's Encrypt 供应的证书只有90天的有效期,我们必须在这些证书过期之前重新得到它们。
有什么办法呢?

certbot 给我们供应了一个很方便的命令,那便是

certbot renew # 利用【默认配置目录】的更新命令certbot renew --config-dir /etc/nginx/conf.d/certs # 利用【自定义配置目录】的更新命令

  利用此命令,他将自动检讨系统中的证书并自动更新它们。

把稳:

  更新完成后须要重启Nginx:nginx -s reload。
  我们可以运行这个命令测试一下

certbot renew --dry-run如果运行的时候涌现了这个缺点:

Attempting to renew cert from /etc/letsencrypt/renewal/api.diamondfsd.com.conf produced an unexpected error: At least one of the required ports is already taken.. Skipping.

  这是由于天生证书的时候利用的是 --standalone 模式。
  这个模式在验证域名时,此模式须要启用端口443。
此缺点意味着要启用的端口已被占用。

  这时候必须先关掉nginx,运行以下命令:

nginx -s stop

  运行这个命令,没有报错的话,也便是所有的证书都刷新成功。
证书是90天才过期,我们只须要在过期之前实行更新操作就可以了。
  当然,这种不用我们每次去更新,我们随意马虎忘却的,可以用linux的定时任务来完成。
用 crontab做一个定时任务就可以了

  写上 cron 操持:编写如下任务详情

15 2 /2 certbot renew --pre-hook "nginx -s stop" --post-hook "nginx -s start" # standalone模式15 2 /2 certbot renew --post-hook "nginx -s reload"

# 非standalone模式命令的意思便是:每隔 两个月的 凌晨 2:15 实行更新操作。
--pre-hook 表示实行更新操作之前要做的事情。
--standalone模式的证书须要停滞 nginx 做事,解除端口占用。
--post-hook 表示实行更新操作完成后要做的事情,这里就规复 nginx 做事的启用

  末了我们用 crontab -e 打开 linux 定时任务添加

15 2 /2 certbot renew --pre-hook "nginx -s stop" --post-hook "nginx -s start" # standalone模式15 2 /2 certbot renew --post-hook "nginx -s reload"

  至此,全体网站升级到HTTPS就完成了。

6 删除证书

  删除所有证书:

$ sudo certbot delete

  删除指定证书:

$ sudo certbot delete --cert-name example.com

  删除指定目录下的指定证书:

$ certbot delete --cert-name example.com --config-dir /etc/nginx/conf.d/certs

0

标签:

相关文章