部署支持 https 的 Nginx 服务
通过 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 服务的更多相关文章
- 用Docker搭建一个支持https的nginx代理服务
用Docker搭建一个支持https的nginx代理服务 说明:本文所提的服务只是作者平常测试使用,可能含有未知bug或不成熟的解决方案,仅供参考,请不要用于正式环境,当然,使用过程中有任何问题欢迎提 ...
- 【k8s】使用k8s部署一个简单的nginx服务
名词解释 Namespace 表示命名空间 Deployment 表示pod发布 Service 表示多个pod做为一组的集合对外通过服务的表示 kubectl 是k8s的命令行操作命令,可以创建和更 ...
- 让你的网站免费支持 HTTPS 及 Nginx 平滑升级
为什么要使用 HTTPS ? 首先来说一下 HTTP 与 HTTPS 协议的区别吧,他们的根本区别就是 HTTPS 在 HTTP 协议的基础上加入了 SSL 层,在传输层对网络连接进行加密.简单点说在 ...
- nginx安装部署(支持https)
1 安装环境准备 1.1 准备环境清单 以下是基本环境清单列表: 软件名称 版本号 说明信息 Linux CentOS 6.7 部署机器只需为Linux系统即可,无严格要求 1.2 ...
- Linux下源码安装Nginx服务
nginx 安装 linux 系统需要安装必备的开发包,比如 gcc,gcc-c++ 1. openssl (支持 https) https://www.openssl.org/source/ ...
- nginx服务部署 说明
第1章 常用的软件 1.1 常用来提供静态服务的软件 Apache :这是中小型Web服务的主流,Web服务器中的老大哥, Nginx :大型网站Web服务的主流,曾经Web服务器中的初生牛犊 ...
- Nginx部署部分https与部分http【转】
转自 Nginx部署部分https与部分http - na_tion的专栏 - 博客频道 - CSDN.NEThttp://blog.csdn.net/na_tion/article/details/ ...
- Nginx服务部署
1 企业常用网站服务 处理静态资源:nginx.apache.Lighttpd处理动态资源:tomcat(java语言编写).php(php语言编写).python(python语言编写)nginx网 ...
- Nginx安装配置|Nginx反向代理|Nginx支持HTTPS|Nginx重定向
Nginx安装配置 可以直接看到最下面的HTTPS. Nginx安装 我的系统如下: No LSB modules are available. Distributor ID: Ubuntu Desc ...
随机推荐
- Notepad++找回Plugin Manager{在v7.50后(包括7.50)不带有插件管理器(Plugin Manager)}
https://github.com/notepad-plus-plus/notepad-plus-plus/issues/2459 64 bit Plugin Manager is now avai ...
- Linux列举所有隐藏文件
ll 命令是 ls -l的缩写 ls -a是列举所有(all)文件,包含隐藏文件,以.开头的文件. ls -l是以列表(list)方式列举文件. http://bbs.chinaunix.net/th ...
- 如何删除GitHub或者GitLab 上的文件夹
如何删除GitHub或者GitLab 上的文件夹 需求分析 假设小明有一天不小心把本地仓库的一个文件夹A推送到了远程GIT服务器(例如:github,gitlab,gitee)上,此时想删除远程仓 ...
- ionic3应用的Android打包签名发布步骤
版权声明:本文为博主原创文章,未经博主允许不得转载. 当我们的ionic应用开发结束之后,就要开始上线到应用市场,那么Android的发布步骤具体是怎么样的呢? 1)编译 运行命令行: ionic c ...
- Linux常用指令-ssh
目录 ssh远程登陆 ssh免密码登陆 生成公钥和私钥 将公钥复制到其他从机 文件说明 id_rsa id_rsa.pub authorized_keys known_host SSH(远程连接工具) ...
- delphi 的 LockType 锁类型
LockType 锁类型 常数 值 说明 ...
- JavaScript——AJAX
AJAX技术是网页构建的必备技能之一,本文希望能帮助大家轻松的学习这项技术 一.什么是ajax? ajax(异步javascript xml) 能够刷新局部网页数据而不是重新加载整个网页. 二.如何使 ...
- fix
rounds the elements of A toward zero, resulting in an array of integers. For complex A, the imaginar ...
- VMware vCenter 6.0 安装及群集配置介绍
一.介绍 VMware vCenter Server 提供了一个可伸缩.可扩展的平台,为虚拟化管理奠定了基础.可集中管理VMware vSphere环境,与其他管理平台相比,极大地提高了 IT 管理员 ...
- 25 行 Python 代码实现人脸识别——OpenCV 技术教程
OpenCV OpenCV 是最流行的计算机视觉库,原本用 C 和 C++ 开发,现在也支持 Python. 它使用机器学习算法在图像中搜索人的面部.对于人脸这么复杂的东西,并没有一个简单的检测能对是 ...