Nginx配置https原理及实现过程详解

Nginx配置https原理及实现过程详解,第1张

Nginx配置https原理及实现过程详解

本文介绍了Nginxhttps配置的基本原理以及整个过程的详细说明。原文根据示例代码非常详细,对大家的学习培训或者工作都有一定的参考价值,朋友们一定要参考。

使用linux常用工具certbot生成https证书。

这个特殊的工具是用来生成加密证书的。

咱们加密就是数据证书的权威认证。Let'sEncrypt是网络安全科研工作组(ISRG,一家慈善机构)推出的一个服务项目。

显示完全免费的SSL/TLS证书

2015年12月3日,服务项目进入第一次测试环节,并向群众公布。

2016年4月12日,新项目宣布脱离Beta版。

到2016年9月9日,Let'sEncrypt已经发放了1000份介绍马匹到镇上的证书。

所以对于绝大多数大中小网站来说,都是非常值得选择的。

HTTPS配置过程

1打开https://certbot.eff.org/选择匹配计算机 *** 作系统和Web服务器。

这里我选择nginx服务器,在CentOS7服务器上

运行命令,根据需要更改相关网站域名的主要参数。

Certbot要按照yum安装,certbot打包成epel源码。

因此,安装启动epel库并安装epel源查询连接

https://fedoraproject.org/wiki/EPEL#How_can_I_use_these_extra_packages.3f

要启动epel源代码,您可以自己手动启动epel,也可以通过yum-config-manager命令启动EPEL。

安装yum-config-manager

yum-y安装yum-utils

启动epel

yum-config-manager-enablerhui-REGION-rhel-server-extrasrhui-REGION-rhel-server-optional

3安装certbot

sudoyum安装certbotpython2-certbot-nginx

获取证书的两种方法:验证器和安装程序进程。

用webRoot软件安装,规定你的服务器80端口可以正常浏览(这个域名是你的)。

webRoot软件根据certonly和-webroot(或-w)在cmd上运行命令。

certbotcertonly-w/var/www/example-dwww.example.com

Certbotcertonly-wwebroot文件目录,可以通过要配置https的网站的http-d域名浏览

上面的/var/www/example指明了根节点在nginx配置文档中偏向的根路径。

webroot软件的原理是建立一个临时文件夹${webroot-path}/。每个必需领域的知名/极致挑战。

然后Let的数据加密认证服务器发出HTTP请求,认证每个被请求域的DNS是否解析为运行certbot的服务器。

浏览要求如下

66.133.109.36--[05/Jan/2016:20:11:24-0500]"GET/。知名/acme-challenge/hgr8u1ietw4ky_z6uiyaakzokyqgpr_7arlgtze8sxHTTP/1.1"20087"-""Mozilla/5.0(兼容;让我们加密验证服务器;https://www.letsencrypt.org)"

所以每个人的服务器都必须打开的浏览通道。众所周知/极致挑战。

举个例子,

server { listen80; server_namewww.example.com; indexindex.html; root/var/www/example; 。。。 location~/.well-known{ allowall; } }

的实际http配置文档

server { listen80; server_namewww.example.com; indexindex.html; root/var/www/www.example.com; location/{ proxy_redirectoff; proxy_passhttp://localhost:8080; proxy_set_headerHost$host; proxy_set_headerX-real-ip$remote_addr; proxy_set_headerX-Forwarded-For$proxy_add_x_forwarded_for; } #error_page404/404.html; location/nginx_status { #stub_statuson; #access_logoff; } location~/.well-known{ allowall; } location~/\. { denyall; } access_log/data/log/nginx//var/www/www.example.com/-access.log; error_log/data/log/nginx//var/www/www.example.com/-error.log; }

指令实现后,https证书将在/etc/letsencrypt/live文件目录下生成。

certbotcertonly-w/var/www/example-dwww.example.com

例如,上面的指令将生成证书/etc/letsencrypt/live/www.example.com/fullchain.PEM。

生成证书密钥文档/etc/letsencrypt/live/www.example.com/privkey.PEM。

然后你只需要给网站域名加上https配置,nginx配置https。

Https匹配端口443

实际https配置文档

server { listen443sslhttp2; #listen[::]:443sslhttp2; server_namewww.example.com; indexindex.htmlindex.htmindex.phpdefault.htmldefault.htmdefault.php; root/var/www/www.example.com/; sslon; ssl_certificate/etc/letsencrypt/live/www.example.com/fullchain.pem; ssl_certificate_key/etc/letsencrypt/live/www.example.com/privkey.pem; location/{ proxy_redirectoff; proxy_passhttp://localhost:8080; proxy_set_headerHost$host; proxy_set_headerX-real-ip$remote_addr; proxy_set_headerX-Forwarded-For$proxy_add_x_forwarded_for; } #error_page404/404.html; includeenable-php-pathinfo.conf; location~/.well-known{ allowall; } location~/\. { denyall; } access_log/data/log/nginx/www.example.com-ssl-access.log; error_log/data/log/nginx/www.example.com-ssl-error.logs; }

查询制造证书

tree/etc/letsencrypt/live/

证书签名

Let'sEncrypt生成的完全免费证书有效期为3个月,但我们可以无限期更新签证证书

证书更新

应用计时器来完全自动地重新生成证书

00,12***python-c'导入随机;导入时间;time.sleep(random.random()*3600)'&;&证书更新

centos6应用程序

1获取certbot移动客户端

wgethttps://dl.eff.org/certbot-auto
chmodaxcertbot-auto

终止nginx

服务nginx停止

3生成证书

。/certbot-autocertonly-standalone-email`您的电子邮件地址`-d`您的域名地址`

今天的网站应该是在有几个网站域名的情况下后期推广,比如

。/certbot-autocertonly-standalone-email`您的电子邮件地址`-d`您的网站域名1`-dd`您的网站域名2`。

文章里的内容就这些了。期待对大家的学习和培训有所帮助,也期待大家的应用。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zz/774287.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-03
下一篇 2022-05-03

发表评论

登录后才能评论

评论列表(0条)

保存