通过 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. Resolved validation conflict with readonly

    /** * Bug绕过去方案WorkAround * Bug描述: * JQuery的Validation的和form的input元素设为readonly,一对不可调和的矛盾: * 一个设置为requ ...

  2. react + dva + ant架构后台管理系统(一)

    一.什么是dva dva是蚂蚁金服推出的一个单页应用框架,对 redux, react-router, redux-saga进行了上层封装,没有引入新的概念,但是极大的程度上提升了开发效率: 二.安装 ...

  3. GS环境里面 9999 常用密码的加密后的值

    1. Test6530 APTZ5s6vrw1dglqO/63osA== 2. aaaaaa zgnewZXGGoqcPGtNpXTSXQ== 3. cwpass 3Me34S0+zY4xEGUFtz ...

  4. Bootstrap 引入文件顺序及IE兼容性js

    <!DOCTYPE html><html lang="zh-cn"><head> <meta charset="utf-8&qu ...

  5. panda迭代

    1.注意 - 不要尝试在迭代时修改任何对象.迭代是用于读取,迭代器返回原始对象(视图)的副本,因此更改将不会反映在原始对象上. 2.itertuples()方法将为DataFrame中的每一行返回一个 ...

  6. Ubuntu 16.04安装Maven

    此篇为http://www.cnblogs.com/EasonJim/p/7139275.html的分支页. 前提:必须正确安装JDK. 一.通过二进制包(tar.gz)安装 下载: 进入下载列表:h ...

  7. ceph S3客户端操作--s3cmd

    S3 client 访问ceph rgw 安装: yum install s3cmd 验证安装是否成功: $s3cmd --version s3cmd version 1.5.2 #表示安装成功 在c ...

  8. BZOJ4530[Bjoi2014]大融合——LCT维护子树信息

    题目描述 小强要在N个孤立的星球上建立起一套通信系统.这套通信系统就是连接N个点的一个树. 这个树的边是一条一条添加上去的.在某个时刻,一条边的负载就是它所在的当前能够 联通的树上路过它的简单路径的数 ...

  9. BZOJ1468Tree——点分治

    题目描述 给你一棵TREE,以及这棵树上边的距离.问有多少对点它们两者间的距离小于等于K 输入 N(n<=40000) 接下来n-1行边描述管道,按照题目中写的输入 接下来是k 输出 一行,有多 ...

  10. Vue模板 script部分

    <script> export default { name: "Home", data() { return {}; }, methods: { // 组件的方法 } ...