Linux上配置HTTPS 您所在的位置:网站首页 web系统的默认访问协议 Linux上配置HTTPS

Linux上配置HTTPS

2024-04-30 00:32| 来源: 网络整理| 查看: 265

 

一.HTTP简介

       HTTP即超文本传输协议(Hypertext Transfer Protocol)。

       这是一个文件的传输协议,我们上网的时候,所有的文件都是通过HTTP这个协议,从服务器上传输到客户端的电脑里面的。同时HTTP协议工作在应用层,所以想要运行这个协议必须有相应的应用程序支撑。

    这里我们就先了解下什么是客户端,什么是服务端

    客户端:通常是指我们的浏览器,比如谷歌浏览器、火狐浏览器、IE等,浏览器安装在客户使用的电脑上,所以,在描述http时,客户端通常也代指那些安装了浏览器的电脑。

    服务端:通常是指那些安装了web服务软件的计算机,如httpd apache,nginx,lighttpd,这些服务端的计算机被称为服务器。

    当我们从客户端到服务端拉取文件时,这些服务器就会根据你的请求命令给你返回你所需要的资源。而这些资源在传输过程中都会以静态的html格式文件传输,同时它的传输方式是明文的。这样的传输方式就会使你的一些重要信息被一些有心人截取下来,所以基于http的传输方式并不是安全的。这就使HTTPS得以出现。

 

二.HTTPS简介

    HTTPS(全称:httpover ssl,Hyper Text Transfer Protocol over Secure Socket Layer),HTTPS简单来说就是http+ssl,基于安全套接字层的超文本传输协议。它是以安全为目标的HTTP通道,简单讲就是HTTP的安全版。即在HTTP下加入了SSL子层,HTTPS的安全基础是SSL。SSL会使用各种对称加密算法、非对称加密算法来加密传送数据。

 

三.HTTP与HTTPS区别

       区别就是在于https这个多出来的 s。SSL及其继任者传输层安全是为网络通信提供安全及数据完整性的一种安全协议。TLS与SSL在传输层对网络连接进行加密。        其他要说很明显能感觉到的,就是:                - http默认端口是80,https是443                - http不会对传输的数据进行加密,https会。

 

四.SSL会话的简单过程

       (1) 客户端发送可供选择的加密方式,并向服务器请求证书;       (2) 服务器端发送证书以及选定的加密方式给客户端;       (3) 客户端取得证书并进行证书验正:       如果信任给其发证书的CA:               (a) 验正证书来源的合法性;用CA的公钥解密证书上数字签名;               (b) 验正证书的内容的合法性:完整性验正               (c) 检查证书的有效期限;               (d) 检查证书是否被吊销;               (e) 证书中拥有者的名字,与访问的目标主机要一致;        (4) 客户端生成临时会话密钥(对称密钥),并使用服务器端的公钥加密此数据发送给服务器,完成密钥交换;        (5) 服务用此密钥加密用户请求的资源,响应给客户端;

      注意:SSL会话是基于IP地址创建;所以单IP的主机上,仅可以使用一个https虚拟主机;

 

五.HTTPS的实现

1.安装专门的mod_ssl模块

[root@contos7 ~]# yum install mod_ssl Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile Resolving Dependencies --> Running transaction check ---> Package mod_ssl.x86_64 1:2.4.6-80.el7.centos will be installed --> Finished Dependency Resolution Dependencies Resolved ====================================================================================================================== Package Arch Version Repository Size ====================================================================================================================== Installing: mod_ssl x86_64 1:2.4.6-80.el7.centos base 111 k Transaction Summary ====================================================================================================================== Install 1 Package Total download size: 111 k Installed size: 224 k Is this ok [y/d/N]: y Downloading packages: mod_ssl-2.4.6-80.el7.centos.x86_64.rpm | 111 kB 00:00:00 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : 1:mod_ssl-2.4.6-80.el7.centos.x86_64 1/1 Verifying : 1:mod_ssl-2.4.6-80.el7.centos.x86_64 1/1 Installed: mod_ssl.x86_64 1:2.4.6-80.el7.centos Complete!

2.申请CA证书

    要生成证书就需要为服务端生成私钥,并用它来为其提供证书文件;

[root@contos7 ~]# cd /etc/pki/CA [root@contos7 /etc/pki/CA]# (umask 066;openssl genrsa -out private/cakey.pem 4096) Generating RSA private key, 4096 bit long modulus .....++ .........................................................++ e is 65537 (0x10001) [root@contos7 /etc/pki/CA]# openssl req -new -x509 -key private/cakey.pem -out cacert.pem -days 3650 You are about to be asked to enter information that will be incorporated into your certificate request. What you are about to enter is what is called a Distinguished Name or a DN. There are quite a few fields but you can leave some blank For some fields there will be a default value, If you enter '.', the field will be left blank. ----- Country Name (2 letter code) [XX]:CN State or Province Name (full name) []:HeNan Locality Name (eg, city) [Default City]:ZhengZhou Organization Name (eg, company) [Default Company Ltd]:Magedu Organizational Unit Name (eg, section) []:opt Common Name (eg, your name or your server's hostname) []: Email Address []: [root@contos7 /etc/pki/CA]# touch index.txt [root@contos7 /etc/pki/CA]# echo 00 > serial [root@contos7 /etc/pki/CA]# mkdir /etc/httpd/conf.d/ssl [root@contos7 /etc/pki/CA]# cd /etc/httpd/conf.d/ssl/ [root@contos7 /etc/httpd/conf.d/ssl]# (umask 066;openssl genrsa -out httpd.key 1024) Generating RSA private key, 1024 bit long modulus ......++++++ .............++++++ e is 65537 (0x10001) [root@contos7 /etc/httpd/conf.d/ssl]# openssl req -new -key httpd.key -out httpd.csr [root@contos7 /etc/httpd/conf.d/ssl]# openssl ca -in httpd.csr -out httpd.crt -days 365 [root@contos7 /etc/httpd/conf.d/ssl]# cp /etc/pki/CA/cacert.pem .

3.编辑.conf配置文件

    将代码修改为下列三行

[root@contos7 ~]# vim /etc/httpd/conf.d/ssl.conf SSLCertificateFile /etc/httpd/conf.d/ssl/httpd.crt SSLCertificateKeyFile /etc/httpd/conf.d/ssl/httpd.key SSLCACertificateFile /etc/httpd/conf.d/ssl/cacert.pem

4.修改配置文件

[root@contos7 ~]# vim /etc/httpd/conf.d/vhost.conf ServerName www.baidu.com DocumentRoot "/app/website1" CustomLog "logs/www.baidu.com_access_log" combined Require all granted ~

4.重新启动服务

[root@contos7 ~]# systemctl restart httpd

 



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有