在Apache HTTP服务器上配置 TLS加密

  1. 安装mod_ssl软件包
bash 复制代码
[root@localhost conf.d]# dnf install mod_ssl -y

此时查看监听端口多了一个443端口

  1. 自己构造证书
bash 复制代码
[root@localhost conf.d]# cd /etc/pki/tls/certs/
[root@localhost certs]# openssl genrsa > jiami.key
[root@localhost certs]# openssl req -utf8 -new -key jiami.key -x509 -days 100 -out jiami.crt
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]:86
State or Province Name (full name) []:shaaxi
Locality Name (eg, city) [Default City]:xi'an
Organization Name (eg, company) [Default Company Ltd]:rhce
Organizational Unit Name (eg, section) []:peihua
Common Name (eg, your name or your server's hostname) []:www.hehe.com
Email Address []:admin@hehe.com
[root@localhost certs]# mv jiami.key ../private/
[root@localhost certs]# cd -
/etc/httpd/conf.d
[root@localhost conf.d]# ll
total 32
-rw-r--r--. 1 root root 2916 Jul 20  2023 autoindex.conf
-rw-r--r--. 1 root root  400 Jul 20  2023 README
-rw-r--r--. 1 root root 8720 Jul 20  2023 ssl.conf
-rw-r--r--. 1 root root 1252 Jul 20  2023 userdir.conf
-rw-r--r--. 1 root root 1171 Jul  5 15:41 vhost.conf
-rw-r--r--. 1 root root  653 Jul 20  2023 welcome.conf

修改配置文件

bash 复制代码
[root@localhost conf.d]# vim ssl.conf 

重启服务

bash 复制代码
[root@localhost conf.d]# systemctl restart httpd

测试

  1. 在vhost.conf配置文件中添加信息
  1. 测试
    之前在/www/hehe/index.html里写的东西现在还都能访问,证书也构造成功。


在本地访问需要在本地解析文件中添加www.hehe.com主机名

bash 复制代码
[root@localhost conf.d]# vim /etc/hosts
bash 复制代码
[root@localhost conf.d]# curl -k https://www.hehe.com
welcome to hehe
相关推荐
爱编程的鱼2 小时前
403 是什么意思?一文读懂 HTTP 状态码 403 及解决方法
网络·网络协议·http
Unstoppable222 小时前
八股训练营第 8 天 | TCP连接三次握手的过程?TCP连接四次挥手的过程?HTTP的Keep-Alive是什么?
网络·tcp/ip·http·八股
视觉AI2 小时前
HTTP 请求与数据交互全景指南:Request、GET、POST、JSON 及 curl
http·json·交互
_dindong2 小时前
Linux网络编程:应用层协议HTTP
网络·网络协议·http
Jerry2505093 小时前
什么是HTTPS?对网站有什么用?
网络·网络协议·http·网络安全·https·ssl
0和1的舞者3 小时前
网络的奥秘:HTTPS详解(八)
网络·网络协议·tcp/ip·http·https·四大件
java_logo3 小时前
HashiCorp Vault 镜像拉取与 Docker 部署全指南
运维·docker·容器
chxii3 小时前
spring boot 获取HTTP 请求参数
spring boot·后端·http
Maple_land4 小时前
Linux复习:冯·诺依曼体系下的计算机本质:存储分级与IO效率的底层逻辑
linux·运维·服务器·c++·centos
Macbethad5 小时前
用流程图去描述一个蓝牙BLE数字钥匙的初始化连接过程
服务器·网络·流程图