通过 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.com You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=www.xxxx.com
https://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

在浏览器中打开站点,就能看到地址栏上的小绿锁了~


原文发布于 https://blog.moonlightwatch.me/linux/2018/08/30/nginx-https/

部署支持 https 的 Nginx 服务的更多相关文章

  1. 用Docker搭建一个支持https的nginx代理服务

    用Docker搭建一个支持https的nginx代理服务 说明:本文所提的服务只是作者平常测试使用,可能含有未知bug或不成熟的解决方案,仅供参考,请不要用于正式环境,当然,使用过程中有任何问题欢迎提 ...

  2. 【k8s】使用k8s部署一个简单的nginx服务

    名词解释 Namespace 表示命名空间 Deployment 表示pod发布 Service 表示多个pod做为一组的集合对外通过服务的表示 kubectl 是k8s的命令行操作命令,可以创建和更 ...

  3. 让你的网站免费支持 HTTPS 及 Nginx 平滑升级

    为什么要使用 HTTPS ? 首先来说一下 HTTP 与 HTTPS 协议的区别吧,他们的根本区别就是 HTTPS 在 HTTP 协议的基础上加入了 SSL 层,在传输层对网络连接进行加密.简单点说在 ...

  4. nginx安装部署(支持https)

    1      安装环境准备 1.1   准备环境清单 以下是基本环境清单列表: 软件名称 版本号 说明信息 Linux CentOS 6.7 部署机器只需为Linux系统即可,无严格要求 1.2   ...

  5. Linux下源码安装Nginx服务

    nginx 安装 linux 系统需要安装必备的开发包,比如 gcc,gcc-c++     1. openssl (支持 https) https://www.openssl.org/source/ ...

  6. nginx服务部署 说明

    第1章 常用的软件 1.1 常用来提供静态服务的软件   Apache :这是中小型Web服务的主流,Web服务器中的老大哥,   Nginx :大型网站Web服务的主流,曾经Web服务器中的初生牛犊 ...

  7. Nginx部署部分https与部分http【转】

    转自 Nginx部署部分https与部分http - na_tion的专栏 - 博客频道 - CSDN.NEThttp://blog.csdn.net/na_tion/article/details/ ...

  8. Nginx服务部署

    1 企业常用网站服务 处理静态资源:nginx.apache.Lighttpd处理动态资源:tomcat(java语言编写).php(php语言编写).python(python语言编写)nginx网 ...

  9. Nginx安装配置|Nginx反向代理|Nginx支持HTTPS|Nginx重定向

    Nginx安装配置 可以直接看到最下面的HTTPS. Nginx安装 我的系统如下: No LSB modules are available. Distributor ID: Ubuntu Desc ...

随机推荐

  1. 用delete和trancate删除表记录的区别

    首先说相同点,就是他们都能删除表中的数据,区别有两点: 第一点: delete语句在删除记录的时候可以有选择的删除某些数据(使用where子句),当然,如果不添加where子句,就是删除所有记录 而t ...

  2. PDF文档打印太慢怎么办

    如下图,用Adobe Acrobat打开PDF文件,然后[高级]-打勾[作为图像打印]即可

  3. [转帖]以Windows服务方式运行ASP.NET Core程序

    以Windows服务方式运行ASP.NET Core程序 原作者blog: https://www.cnblogs.com/guogangj/p/9198031.htmlaspnet的blog 需要持 ...

  4. [转帖]速度快散热好 为什么U.2 SSD还没普及?

    速度快散热好 为什么U.2 SSD还没普及?   经典的影视剧中总有那么几位武林高手,江湖上只闻其名,不见其形.今天我们要聊的这位爷,誓要拳打南山M.2,脚踩北海SATA 3!它就是固态硬盘界久负盛名 ...

  5. 简单对比一下不同Windows操作系统在相同硬件配置的情况下浏览器js引擎的性能

    最近部门进行Windows客户端的测试产品单点性能, 感觉不在通的windows版本以及浏览器内核的情况下性能可能有差异, 也一直没有找到一个比较好的对比工具, 今天用chrome的控制台简单测试了下 ...

  6. Qt开发之信号槽机制

    一.信号槽机制原理 1.如何声明信号槽 Qt头文件中一段的简化版: class Example: public QObject { Q_OBJECT signals: void customSigna ...

  7. delphi中ini 文件操作记要(1): 使用 TIniFile

    unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms ...

  8. BZOJ3832[Poi2014]Rally——权值线段树+拓扑排序

    题目描述 An annual bicycle rally will soon begin in Byteburg. The bikers of Byteburg are natural long di ...

  9. openfalcon架构及相关服务配置详解

    一:openfalcon组件 1.falcon-agent 数据采集组件 agent内置了一个http接口,会自动采集预先定义的各种采集项,每隔60秒,push到transfer. 2.transfe ...

  10. bzoj 2120 数颜色 (带修莫队)

    题目链接: https://www.lydsy.com/JudgeOnline/problem.php?id=2120 题意:两种操作:Q 询问区间  l - r  内颜色的种类 ,R 单点修改 思路 ...