Apache加密

发布时间 2023-12-03 10:44:16作者: 代码你敲我不敲

配置TLS加密的虚拟主机(443/TLS)

SSl提供了3中服务,保证数据的安全传输

认证用户和服务器,确保数据发送到正确的客户机和服务器;
加密数据以防止数据中途被窃取;
维护数据的完整性,确保数据在传输过程中不被改变

客户使用https的URL访问Web服务器,要求与Web服务器建立SSL连接。
Web服务器收到客户端请求后,会将网站的证书信息(证书中包含公钥)传送一份给客户端。
客户端的浏览器与Web服务器开始协商SSL连接的安全等级,也就是信息加密的等级。
客户端的浏览器根据双方同意的安全等级,建立会话密钥,然后利用网站的公钥将会话密钥加密,并传送给网站。
Web服务器利用自己的私钥解密出会话密钥。
Web服务器利用会话密钥加密与客户端之间的通信。

1.安装加密软件(使网站不用明文传输)

yum -y install  mod_ssl

2.生成密钥

openssl genrsa >tlsweb.key

3.生成证书请求文件

[root@server ~]# openssl req -new -key tlsweb.key  >tlsweb.csr
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]:
State or Province Name (full name) []:
Locality Name (eg, city) [Default City]:
Organization Name (eg, company) [Default Company Ltd]:
Organizational Unit Name (eg, section) []:
Common Name (eg, your name or your server's hostname) []:
Email Address []:

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
[root@server ~]#

3.生成证书文件
openssl req -x509 -days 365 -key tlsweb.key -in tlsweb.csr >tlsweb.crt

5.修改ssl.conf配置文件

vim /etc/httpd/conf.d/ssl.conf

 SSLCertificateFile /etc/pki/tls/certs/tlsweb.crt
      SSLCertificateKeyFile /etc/pki/tls/private/tlsweb.key

6.把证书文件copy到ssl.conf配置文件里的对应路径

cp tlsweb.crt /etc/pki/tls/certs/

7.把密钥文件copy到ssl.conf配置文件里的对应路径

cp tlsweb.key /etc/pki/tls/private/

8.重启服务

    systemctl restart httpd

9.访问
image
访问出错