一.实现https加密
我们知道现在到了 https 的时代了,每个优秀的网站几乎都已经开启 https。开启了 https 加密访问之后,登录你的网站,浏览器地址栏就会出现一把绿色的锁,这就是使用了超文本传输安全协议(HTTPS),是以安全为目标的HTTP通道,简单来说就是HTTP安全版。
https由两个部分组成:HTTP+SSL/TLS,在http基础上加上了一层加密信息模块,服务端和客户端的信息插损胡都会通过TLS进行加密,传输的数据都是加密后的数据
为了解决HTTP协议的这些缺陷,需要使用另一种协议:HTTPS。为了数据传输的安全性,HTTPS在http的基础上加了SSL协议,SSL依靠证书验证身份,并为浏览器和服务器之间通信加密;
SSL证书是一种数字证书,使用Secure Socket Layer协议在浏览器和web服务器之间建立一条安全通道,从而实现数据信息在客户端和服务器之间的加密传输,保证双方传递信息的安全性,不可被第三方窃听,而且用户可以通过服务器证书验证所访问网站是否真实可靠;
加密的HTTPS和HTTP的区别:
- 超文本传输协议HTTP协议被用于在web浏览器和网站服务器之间传递信息,HTTP协议以明文方式发送内容,不提供任何方式的加密数据,如果攻击者截取了web浏览器和网站服务器之间的传输报文,就可以直接读取其中信息,因此,http协议不适合传输一些敏感信息;
实验如下所示:
第一步:1.关闭nginx服务,并重新编译(主要是为了添加ssl模块)
[root@nodel1 conf]# systemctl stop nginx
[root@nodel1 conf]# cd /mnt
[root@nodel1 mnt]# ls
[root@nodel1 mnt]# cd nginx-1.17.1/
[root@nodel1 nginx-1.17.1]# make clean
[root@nodel1 nginx-1.17.1]# yum install openssl-devel -y #编译过程使用加密的时候,需要安装这个
[root@nodel1 nginx-1.17.1]# ./configure --prefix=/usr/local/nginx --with-http_realip_module --with-http_image_filter_module=dynamic --with-http_ssl_module
[root@nodel1 nginx-1.17.1]# make
替代之前的二进制文件并再次将图像模块放入modules目录下
[root@nodel1 nginx-1.17.1]# cd objs/
[root@nodel1 objs]# cp nginx -f /usr/local/nginx/sbin/nginx
[root@nodel1 objs]# ls
[root@nodel1 objs]# cp ngx_http_image_filter_module.so /usr/local/nginx/modules
第二步:在/etc/pki/tls/certs/下生成证书并将证书都放到nginx的配置文件的目录下
[root@nodel1 objs]# cd /etc/pki/tls/certs/
[root@nodel1 certs]# make cert.pem #生成证书
Country Name (2 letter code) [XX]:cn # 国家代号,中国输入CN
State or Province Name (full name) []:shannxi #省
Locality Name (eg, city) [Default City]:xi'an #市
Organization Name (eg, company) [Default Company Ltd]:westos #公司英文名
Organizational Unit Name (eg, section) []:linux #组织名称
Common Name (eg, your name or your server's hostname) []:nodel1 #主机名或者你的名字
Email Address []:root@westos.org #邮箱地址
[root@nodel1 certs]# cp cert.pem /usr/local/nginx/conf/ # 将证书都放到nginx的配置文件的目录下