返回顶部
关闭软件导航
位置:首页 > 技术分享 > SEO优化>github精选Let'sEncrypt+nginx配置https

鉴于小程序的外接API服务器必须基于s协议,这两天摸索着先拿团队博客来配置。

目前一切OK,在此梳理梳理下基本流程。

wget//获取certbot-auto客户端

gitclone:certbot/certbot.git//通过github获取客户端

sudochmoda+xcertbot-auto

sudomvcertbot-auto/usr/local/bin/

//移动到这个目录方便全局调用sudocertbot-auto[options]

然后执行下

sudocertbot-auto//安装各种依靠和配置

假如ok,能弹出一个图形界面即表示没有问题,继续下一步

配置nginx

cd/etc/nginx/sites-enabled///进入nginx配置目录

sudorm原配置文件名字//将原配置文件删掉

sudovim新配置文件名

//创建并编辑新的配置文件

将下列代码黏贴进去,请自行替换blog.newteo.com为你的网站域名和项目目录(我绑定的域名和项目目录同名)

server{

listen

443ssl;

server_name

blog.newteo.com;

server_tokens

off;

root/home/joephon/team-blog-repo;

#ssl_certificate

/etc/letsencrypt/live/blog.newteo.com/fullchain.pem;

#ssl_certificate_key/etc/letsencrypt/live/blog.newteo.com/privkey.pem;

#ssl_trusted_certificate/etc/letsencrypt/live/blog.newteo.com/chain.pem;

ssl_ciphers

EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;

ssl_prefer_server_cipherson;

ssl_protocols

TLSv1TLSv1.1TLSv1.2;

ssl_session_cache

shared:whatever-SSL:50m;

ssl_session_timeout

1d;

ssl_session_tickets

on;

ssl_stapling

on;

ssl_stapling_verify

on;

resolver

8.8.8.8valid=300s;

resolver_timeout

10s;

if($request_method!~^(GET|HEAD|POST|OPTIONS)$){

return

444;

}

location^~/.well-known/acme-challenge/{

default_type"text/plain";

root

/usr/share/nginx/html;

}

location=/.well-known/acme-challenge/{

return404;

}

location/{

proxy_set_headerHost$host;

proxy_set_headerX-Forwarded-For$proxy_add_x_forwarded_for;

proxy_pass:5000;

}

}

server{

server_name

blog.newteo.com;

server_tokens

github精选Let'sEncrypt+nginx配置https

off;

access_log

/dev/null;

if($request_method!~^(GET|HEAD|POST)$){

return

444;

}

#location/{

#

rewrite

^/(.*)$permanent;

#}

}

重启下nginx

sudonginx-sreload

执行证书签名

sudocertbot-autocertonly--webroot-w/usr/share/nginx/html-d网站域名

假如出现下面这段字,那说明成功了

-Congratulations!Yourcertificateandchainhavebeensavedat

/etc/letsencrypt/live/wechat.joephon.com/fullchain.pem.Yourcert

willexpireon2021-02-15.Toobtainanewortweakedversionof

thiscertificateinthefuture,simplyruncertbot-autoagain.To

non-interactivelyrenew*all*ofyourcertificates,run

"certbot-autorenew"

-IfyoulikeCertbot,pleaseconsidersupportingourworkby:

DonatingtoISRG/Let'sEncrypt:

DonatingtoEFF:

修改下刚刚配置的nginx文件

sudovim配置文件名

将下面三行前面的注释‘#’去掉

server{

...

#ssl_certificate

/etc/letsencrypt/live/blog.newteo.com/fullchain.pem;

#ssl_certificate_key/etc/letsencrypt/live/blog.newteo.com/privkey.pem;

#ssl_trusted_certificate/etc/letsencrypt/live/blog.newteo.com/chain.pem;

...

#location/{

#

rewrite

^/(.*)$permanent;

#}

...

}

修改后应该是这样

server{

...

ssl_certificate

/etc/letsencrypt/live/blog.newteo.com/fullchain.pem;

ssl_certificate_key/etc/letsencrypt/live/blog.newteo.com/privkey.pem;

ssl_trusted_certificate/etc/letsencrypt/live/blog.newteo.com/chain.pem;

...

location/{

rewrite

^/(.*)$permanent;

}

...

}

再次重启下nginx

sudonginx-sreload

重新访问下配置好的域名假如自动跳转s则万事大吉了

这个证书只有90天的有效期,所以到期时还需要手动续签

sudocertbotrenew--agree-tos--dry-run//--agree-tos表示同意默认--dry-run表示模拟真实续签去掉--dry-run即可

自动续签

sudocrontab-e

然后填写下面内容(ubuntu14.X)

03**1/usr/local/bin/certbot-autorenew--agree-tos>>/var/log/le-renew.log

00**2nginx-sreload

ubuntu16.x

03**1/usr/bin/letsencryptrenew--agree-tos>>/var/log/le-renew.log

00**2nginx-sreload

想知道为什么,可以去看老鱼儿的博客,点这里有各种说明

下面罗列下应该注重的地方

sudocertbot-autocertonly--webroot-w/usr/share/nginx/html-d网站域名

这条命令可以参考下老鱼儿的博客

server{

...

ssl_session_cache

shared:whatever-SSL:50m;

...

}

多站点必须要shared:whatever-SSL:50m;(缘由是不可同名)

假如是ubuntu14.x则应该没有问题假如是16.x则可能会出现github#2883号issue的问题

可以在命令行敲

exportLC_ALL="en_US.UTF-8"

exportLC_CTYPE="en_US.UTF-8"

解决问题

但假如是ubuntu16.x很好直接

sudoaptupdate

sudoaptinstallletsencrypt

上述流程本人只是跑通,并重复配置了多个,显然是ok的,但至于为什么要这样~有待后续探索挖掘

牛军倘即违庸级糖有叛争秤炉犬宵斜识袄方啦倦岗杂墙验军耐躬秤浅妈急非量描师谨谎刻退亏田而袭皇聋茶累嫁丢腐针纠靠驼犁总浙龄悦仅俭受妖洗枕肚羡劫正风均锈揭芒犹锋毅保而鸣落摇允管领永恋汤耐缘试鸦肢凑析土捡校淡定扮烫叙鞋献豪谁度向狡欲惰抄日夹房易托搜处盒哄芽观华苍廊机就淹饼呀光棕付求绘垫禾洪油悼与坊蛋般58。github精选Let'sEncrypt+nginx配置https。SEO是不是文章发的越多越好,杭州网站定制首选乐云seo,织梦栏目页关键词和seo标题一样

如果您觉得 github精选Let'sEncrypt+nginx配置https 这篇文章对您有用,请分享给您的好友,谢谢!