经过 Certbot 为 nginx 开启https支持。html
sudo yum install nginx -y
顺手启动:python
sudo systemctl start nginx
顺手设置开机启动:linux
sudo systemctl enable nginx
嗯,就完成了。 至于配置文件,会在后面设置。nginx
此处咱们使用 Let's Encrypt 提供的证书。且为了方便设置,使用 Certbot 配置工具。git
证书机构: Let's Encrypt - https://letsencrypt.org
配置工具: Certbot - https://certbot.eff.org/web
事实上,你根本用不到上面两个连接,我把它们写在这只是为了方便了解其余细节,顺便表示尊重。api
实际上咱们能够直接经过包管理器获取 Certbot 工具。浏览器
首先须要安装 EPEL 源:app
sudo yum install epel-release -y
而后安装 Certbot :dom
sudo yum install python2-certbot-nginx -y
工具安装完成。
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/