给博客加上HTTPS
source link: https://www.qikqiak.com/post/make-https-blog/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
谁都不愿意在使用网站服务的时候,被恶心的运营商劫持加上一些他们的服务(真的很贱,不是吗?),不过这能难道我们程序员吗?当然不能,上https
,老子全站https
,你再劫持给我看看。
https
证书服务大部分都是收费的,而且很贵,阿里云可以申请一个免费的证书,只能绑定一个域名,这里我们使用更加友好的免费https
服务:Let’s Encrypt
Let’s Encrypt 简介
如果要启用HTTPS,我们就需要从证书授权机构(以下简称CA) 处获取一个证书,Let's Encrypt
就是一个 CA。我们可以从Let's Encrypt
获得网站域名的免费的证书。这篇文章也主要讲的是通过 Let's Encrypt + Nginx
来让网站升级到HTTPS
。
Certbot是Let's Encrypt
官方推荐的获取证书的客户端,可以帮我们获取免费的Let's Encrypt
证书。安装命令:
yum install certbot
生成证书:
certbot certonly --email [email protected] --agree-tos --webroot -w /var/www/blogs -d blog.qikqiak.com
其中-w后面是网站根目录,-d后面是网站域名,所以需要保证目录存在并且可以正常访问。
执行完生成证书的命令后,会生成相关的证书文件到/etc/letsencrypt/live/blog.qikqiak.com/
目录下面:
$ ls /etc/letsencrypt/live/blog.qikqiak.com/
cert.pem chain.pem fullchain.pem privkey.pem README
至此证书生成完成。
Nginx 配置https
证书生成完成后,还需要更改我们的Nginx
配置服务,主要是监听443端口,启用SSL
,并配置SSL
的证书路径(公钥,私钥的路径)。如下:
server
{
listen 443;
ssl on;
ssl_certificate /etc/letsencrypt/live/blog.qikqiak.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/blog.qikqiak.com/privkey.pem;
server_name blog.qikqiak.com;
root /home/notes/apps/blog;
index index.html;
}
配置更改过后重新加载Nginx
即可生效:
nginx -s reload
现在我们访问https://blog.qikqiak.com
已经可以正常访问了,但是还有一个问题就是访问http://blog.qikqiak.com
依然还是http
的,所以我们需要配置将http
更改为https
,这样就完美了。这里可以用到之前我们的301跳转来解决这个问题,完整的配置如下:
server {
listen 80;
server_name blog.qikqiak.com;
rewrite ^(.*)$ https://$host$1 permanent;
}
server
{
listen 443;
ssl on;
ssl_certificate /etc/letsencrypt/live/blog.qikqiak.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/blog.qikqiak.com/privkey.pem;
server_name blog.qikqiak.com;
root /home/notes/apps/blog;
index index.html;
}
到这里我们已经将博客https
化了,但是还没有完的,由于Let's Encrypt
证书的有效期只有90天,所以在到期之前我们需要更新整数,certbot
给我们已经提供了这样的更新命令,我们只需要将更新命令添加到crontab
下面定期更新即可:
$ crontab -l
30 5 1 * * root /usr/bin/certbot renew --renew-hook "/usr/sbin/nginx -s reload"
到这一步才算革命成功了~~~ 我们再也不用担心恶心的害虫了~~~
微信公众号
扫描下面的二维码关注我们的微信公众帐号,在微信公众帐号中回复◉加群◉即可加入到我们的 kubernetes 讨论群里面共同学习。
「真诚赞赏,手留余香」
Recommend
-
235
在靠 WF-1000X「降噪豆」引起了颇高的关注度后,这次索尼在 CES 上带来的真 · 无线耳机新品 WF-SP700N 选择加入了一点运动的风格。如之前在发布时介绍的那样,其 IPX4 级别的防水防汗能力可以更好地适应健身时的使用场景。而且按照 Sony 的说法,这也是...
-
82
国外一个老爸为了让宝宝学会的第一句话就是爸爸,在给宝宝读书的每句话前都加上一句“爸爸”,最后宝宝开口的时候,我好像听到什么东西碎了
-
84
奇思妙想 - @EchoChan - 只需要增加通话和短信,当功能手机用。不需要更多的第三方应用。系统不需要是智能系统。只要能依然保持续航很长就行了。有没有人也有这种奇葩需求。手机+墨水屏阅读器二合一。YOTA 虽然是一种
-
92
图形符号在 Markdown 文档中的应用 使用 Markdown 写文档是件赏心悦目的事情,借此可以专注于内容而非格式。只在最后轻松导出,即可收割一份美观的文档。 相关阅读: 想学 M...
-
34
前不久写了一篇题目为《Windows系统监听键盘通过UDP协议控制树莓派小车》的文章在FreeBuf上发表了,当初设计小车控制系统的时候仅仅是为了实现...
-
45
大家都知道,设计一定没有单纯的「感性的设计」与「理性的设计」。 多年以前,我在一本书中读到过这么一段对于绘画和设计异同的描述:...
-
55
见识过刀剑与毒药 痴迷于火药和武器 与他人说话时常怀着恐惧 在每一处景象里看到了灾祸 每一次时钟响起,都会战栗不安 但却未厌恶那不可抗拒的压迫 ——波德莱尔《恶之花》
-
38
【野猪误闯玻璃天桥,吓得不会走路】11月29日,广东清远,一只野生山猪闯入景区玻璃天桥,保安说,“二师兄”可能从没见过玻璃天桥,被吓得趴在桥面上瑟瑟发抖,加上桥上有雾水,“二师兄”后腿“直劈叉”…最终保安把水雾扫干净,把它送回山林。...
-
9
SEO 1 mins给Hugo博客加上baiduurls.txt24-05-20 / 307 Words写作不易,资瓷一下呗!本文首发于个人博客:https://rayc...
-
5
23 July 2021 - 字数统计:1447 - 阅读大约需要5分钟 - Hits: 34 如何给博客加上全文搜索功能 by mayx 原来JavaScript比Java还难?! 前两天,我在看群的时候看到了
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK