前不久重新精简合并了自己的所有服务器,现在所有的服务都整合到了一个服务器上,正好借此机会整理一下建站过程中使用的教程以及记录爬过的坑。
HTTPS现在逐渐成为站点的传输协议规范,很多浏览器在访问旧的http网页时都会提示不安全等内容。因此建立一个规范的https网页就十分必要了。
废话不多说,直接开始教程!
- 安装certbot,并安装nginx用certbot插件
1 2 | sudo apt install certbot sudo apt install python3-certbot-nginx |
- 运行代码来获取tls证书(替换you@example.com 和 www.example.com为你的信息和域名)
1 | sudo certbot --nginx --agree-tos --redirect --hsts --staple-ocsp --email you@example.com -d www.example.com |
其中:
--nginx
: 使用nginx插件--agree-tos
: 同意使用协议--redirect
: 强制http 301重定向--hsts
: 增加tls域名访问--staple-ocsp
: 启动OCSP
运行后会提示你的证书已经成功安装,pem文件被保存到了哪里,这个时候就可以访问你的https网站了。
注意!不是所有的网站都可以用这种方式进行配置,部分网页需要再手动进行配置。
如果使用apache的话,类似的
1 2 3 | sudo apt install certbot sudo apt install python3-certbot-apache sudo certbot --apache --agree-tos --redirect --hsts --staple-ocsp --email you@example.com -d www.example.com |
“使用certbot配置HTTPS”的一个回复