网站首页 > 技术教程 正文
通过 Certbot 为 nginx 开启https支持。
环境
- CentOS 7.1
- python2.x(这玩意系统里本来就有)
安装Nginx
sudo yum install nginx -y顺手启动:sudo systemctl start nginx顺手设置开机启动:sudo systemctl enable nginx
嗯,就完成了。 至于配置文件,会在后面设置。
配置https
此处我们使用 Let's Encrypt 提供的证书。且为了方便设置,使用 Certbot 配置工具。
工具获得
- 证书机构: Let's Encrypt - https://letsencrypt.org
- 配置工具: Certbot - https://certbot.eff.org/ 事实上,你根本用不到上面两个链接,我把它们写在这只是为了方便了解其他细节,顺便表示尊重。
实际上我们可以直接通过包管理器获取 Certbot 工具。
首先需要安装 EPEL 源:
sudo yum install epel-release -y然后安装 Certbot :
sudo yum install python2-certbot-nginx -y
工具安装完成。
使用 Certbot
Certbot 使用命令行中的交互式配置,我们启动它,然后跟着指示一步一步完成就行。
一、 启动 Certbot
通过命令:
sudo certbot --nginx
二、 填写邮箱
在下述提示后,填写你的邮箱地址。Enter email address (used for urgent renewal and security notices) (Enter 'c' to cancel): xxxx@xxxx.com输入你的邮箱地址,回车确定。
三、 同意用户协议
下述提示提醒你阅读并同意用户协议之类的。Please read the Terms of Service at https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf.
You must agree in order to register with the ACME server at https://acme-v02.api.letsencrypt.org/directory- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(A)gree/(C)ancel: A输入字母 A 回车确定。
四、 请求分享你的邮箱
意思是他们会没事给你发发广告邮件。同意就是了 ╮(╯▽╰)╭Would you be willing to share your email address with the Electronic Frontier Foundation, a founding partner of the Let's Encrypt project and the non-profit organization that develops Certbot? We'd like to send you email about our work encrypting the web, EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y输入字母 Y 回车确定。
五、 指定域名
由于我们在安装nginx后没有配置站点,所以此处要求我们提供域名,配置工具会帮我们填写nginx的配置文件。No names were found in your configuration files. Please enter in your domain name(s) (comma and/or space separated) (Enter 'c' to cancel): www.xxxx.com xxx.xxxx.com输入你自己的域名(多个域名中间用空格隔开)回车确定。
六、 重定向
会询问你是不是要把所有http请求重定向到https。当然要了~Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -1: No redirect - Make no further changes to the webserver configuration.2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for new sites, or if you're confident your site works on HTTPS.
You can undo this change by editing your web server's configuration.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2输入数字 2 回车确定。
七、 完成
此时配置已经完成。你可以在接下来的输出中找到如下段落:- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://www.xxxx.com and https://xxx.xxxx.comYou should test your configuration at:https://www.ssllabs.com/ssltest/analyze.html?d=www.xxxx.comhttps://www.ssllabs.com/ssltest/analyze.html?d=xxx.xxxx.com- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -意思就是你已经成功配置了 www.xxxx.com xxx.xxxx.com 两个域名(就是在 步骤五 输入的那两个,当然,你输入了多少个这里就会显示多少个)。并且你可以在 https://www.ssllabs.com/ 这个网站上测试域名的状态。
八、 证书过期
由于 Let's Encrypt 的免费证书有效期是90天,所以你需要每80几天重新申请一次。
Certbot 可以通过简单的命令完成这个工作:
certbot renew
如果你还是觉得麻烦,可以把这个操作设为定时任务,每80几天运行一次,就可以高枕无忧了。
其他
支持https的nginx已经完全配置完成。
接下来把你的站点放在nginx的目录下就行,一般是 /usr/share/nginx/html 如果不是这里,你可以在nginx的配置文件里找到,配置文件位于 /etc/nginx/nginx.conf 。
在浏览器中打开站点,就能看到地址栏上的小绿锁了~
来源:http://www.cnblogs.com/heioray/p/9403246.html
推荐阅读
【资源分享】Docker核心技术视频教程
Java日志体系详细总结
【资源分享】Spring Cloud微服务实战视频课程
docker安装和常用命令&操作
Java视频资料大全
【资源分享】Netty视频教程
Springmvc源码解析总结
Spring IOC体系图和AOP知识脑图
myBatis 体系结构源码解读
你们都在用IntelliJ IDEA吗?或许你们需要看一下这篇博文
本公众号会不定期给大家发福利,包括学习资源等,敬请期待吧!
推送内容如果现在工作用不上,可以先转发朋友圈或收藏,用的时候方便找。
另外欢迎公众号回复微信,添加微信好友,互相学习交流。
猜你喜欢
- 2024-10-11 nginx优化https(ocsp)(nginx配置生成https)
- 2024-10-11 Nginx配置HTTPS(nginx配置带重定向的反向代理)
- 2024-10-11 Linux下配置Nginx并使用https协议
- 2024-10-11 超详解:HTTPS及配置Django+HTTPS开发环境
- 2024-10-11 如何使网站支持https访问?nginx配置https证书
- 2024-09-21 搭建Nginx(Https)+Tomcat实现负载均衡且Https自发证书配置
- 2024-09-21 「python」「nginx」「https」 Nginx 服务器 SSL 证书安装部署
- 2024-09-21 Nginx配置https实现加密认证(https加密证书)
- 2024-09-21 Nginx HTTPS的正反向代理测试(没有为http或https指定代理服务器)
- 2024-09-21 Nginx部署ssl证书开启https简要教程
你 发表评论:
欢迎- 最近发表
-
- Win10 TH2正式版官方ESD映像转换ISO镜像方法详解
- 使用iso镜像升级到Windows 10的步骤
- macOS Ventura 13.2 (22D49) Boot ISO 原版可引导镜像
- 安利一个用ISO镜像文件制作引导U盘的的小工具RUFUS
- CentOS 7使用ISO镜像配置本地yum源
- 用于x86平台的安卓9.0 ISO镜像发布下载:通吃I/A/N、完全免费
- AlmaLinux 9.6发布:升级工具、初步支持IBM Power虚拟化技术
- Rufus写入工具简洁介绍与教程(写入模式)
- 新硬件也能安装使用了,Edge版Linux Mint 21.3镜像发布
- 开源工程师:Ubuntu应该抛弃32位ISO镜像
- 标签列表
-
- 下划线是什么 (87)
- 精美网站 (58)
- qq登录界面 (90)
- nginx 命令 (82)
- nginx .http (73)
- nginx lua (70)
- nginx 重定向 (68)
- Nginx超时 (65)
- nginx 监控 (57)
- odbc (59)
- rar密码破解工具 (62)
- annotation (71)
- 红黑树 (57)
- 智力题 (62)
- php空间申请 (61)
- 按键精灵 注册码 (69)
- 软件测试报告 (59)
- ntcreatefile (64)
- 闪动文字 (56)
- guid (66)
- abap (63)
- mpeg 2 (65)
- column (63)
- dreamweaver教程 (57)
- excel行列转换 (56)
本文暂时没有评论,来添加一个吧(●'◡'●)