apache 设置ssl证书

安装模块

安装mod_ssl和openssl

yum install mod_ssl  openssl  -y

创建密钥存放的目录

mkdir -p /etc/httpd/ssl

chmod 700 /etc/httpd/ssl

上传证书和密钥到/etc/httpd/ssl目录下

验证证书和密钥的MD5

openssl rsa  -noout -modulus -in xxxxxx.key | openssl md5

openssl x509 -noout -modulus -in xxxxxx.crt | openssl md5

编辑配置文件

修改ssl.conf文件

vi /etc/httpd/conf.d/ssl.conf

`````
Listen 443 https

`````

DocumentRoot "网站根目录"

#填写证书名称
ServerName 域名:443

`````

#   Server Certificate:
# Point SSLCertificateFile at a PEM encoded certificate.  If
# the certificate is encrypted, then you will be prompted for a
# pass phrase.  Note that a kill -HUP will prompt again.  A new
# certificate can be generated using the genkey(1) command.
SSLCertificateFile  /etc/httpd/ssl/xxxxxx.crt

#私钥文件的路径

#   Server Private Key:
#   If the key is not combined with the certificate, use this
#   directive to point at the key file.  Keep in mind that if
#   you've both a RSA and a DSA private key you can configure
#   both in parallel (to also allow the use of DSA ciphers, etc.)
SSLCertificateKeyFile  /etc/httpd/ssl/xxxxxx.key
#私钥文件的路径

打开ssl模块功能

/etc/httpd/conf.modules.d 目录下的 00-ssl.conf 配置文件找到 LoadModule ssl_module modules/mod_ssl.so(用于加载 SSL 模块)配置语句,并确认该配置语句未被注释,若已注释,请去掉首行的注释符号(#),保存配置文件。

HTTP 自动跳转 HTTPS 的安全配置

  1. 请确认/etc/httpd/conf/httpd.cof是否存在LoadModule rewrite_module modules/mod_rewrite.so
    • 若存在,请去掉LoadModule rewrite_module modules/mod_rewrite.so前面的注释符号(#)号
    • 若不存在,请您在/etc/httpd/conf.modules.d中新建一个 *.conf 文件,例如 00-rewrite.conf。
LoadModule rewrite_module modules/mod_rewrite.so
  1. 在 相关网站配置文件中添加重定向规则
<Directory "网站根目录"> 
# 新增
RewriteEngine on
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(.*)?$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]
</Directory>

重新启动 Apache 服务器

systemctl restart httpd.service

文章来源:https://www.cnaaa.net,转载请注明出处:https://www.cnaaa.net/archives/6244

(0)
郭靖的头像郭靖
上一篇 2022年11月26日 下午7:30
下一篇 2022年11月29日 下午5:02

相关推荐

  • 系统之眼!Linux系统性能监控工具Glances

    一、Glances介绍 glances是一个基于python语言开发,可以为linux或者UNIX性能提供监视和分析性能数据的功能。glances在用户的终端上显示重要的系统信息,并动态的进行更新,让管理员实时掌握系统资源的使用情况,而动态监控并不会消耗大量的系统资源,比如CPU资源,通常消耗小于2%,glances默认每两秒更新一次数据。同时glances…

    2023年8月15日
    56100
  • Linux firewall防火墙 换成 iptables 防火墙

    一、firewalld 增加开放端口 重启防火墙 二、iptables 增加开放端口 如果要修改防火墙配置,如增加防火墙端口3306 增加规则 保存退出后 最后重启系统使设置生效即可。 三、将firewalld防火墙换成iptables 1、直接关闭防火墙 2、设置 iptables service 如果要修改防火墙配置,如增加防火墙端口3306 增加规则 …

    2023年8月9日
    71100
  • ubuntu20.04 删除linux中软raid的方法

    取消软件 RAID 可能涉及到几个步骤,具体取决于你的操作系统和使用的软件。在大多数 Linux 系统中,mdadm 是用于管理软件 RAID 的常见工具。以下是在 Linux 中取消软件 RAID 的一般步骤: 请注意:在执行这些步骤之前,请确保你已经备份了所有重要数据,因为取消 RAID 可能会导致数据丢失。 查看当前 RAID 状态: 使用以下命令查看…

    2023年11月24日
    76000
  • pve系统崩溃,ceph集群节点不能加入问题处理

    本次故障缘起,pve系统盘突然坏了,导致ceph集群降级,重装pve系统后,发现ceph不能加入原有的集群,需要清除所有配置才可完成 首先需要从集群中删除故障ceph ceph的配置文件路径 /etc/ceph/ceph.conf 此次故障的节点是pve3,在一个正常的节点配置文件中删除故障的节点 同时需要在web页面 监视器中销毁之前故障的节点 osd销毁…

    2024年4月2日
    58700
  • dell服务器使用IDRAC配置RAID独立冗余磁盘阵列步骤

    说明:当硬盘连接到阵列卡(RAID)上时,操作系统将不能直接看到物理的硬盘,因此需要创建成一个一个的被设置为RAID0、1或者5等的逻辑磁盘Logic Drive(也叫容器Container、虚拟磁盘Virtual Drive,不同阵列卡厂商叫法不同) 1.RAID0 是把两块物理盘组合成一块逻辑盘用,因此容量相当于等于二者之和,IO的读写也提高了(因为可以…

    2023年11月30日
    99200

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

在线咨询: QQ交谈

邮件:712342017@qq.com

工作时间:周一至周五,8:30-17:30,节假日休息

关注微信