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

相关推荐

  • ubuntu20.04 删除linux中软raid的方法

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

    2023年11月24日
    18900
  • 虚拟机中进行raid5测试部署

    raid5需要几块硬盘?答案:至少3块。raid5是独立磁盘冗余阵列(raid)种一种,它是用户数据和数据奇偶校验码轮流存储在所有磁盘阵列种的一种体系架构,根据raid5的工作原理,要实现raid5至少需要3块物理磁盘。 原理:每次存储数据时,数据被平均分配到n-1个磁盘中,随机选中一个磁盘生成校验码。当有一个磁盘坏掉时,还可使用其他磁盘进行热备份故障修复;…

    2022年8月16日
    45200
  • Testdisk 取消删除FAT文件

    此恢复示例将指导您逐步使用TestDisk从 FAT (FAT12/FAT16/FAT32) 和 VFAT 文件系统中恢复删除的文件。FAT 主要用于数码相机的存储卡和 USB 闪存盘。VFAT 主要存在于 Windows 下格式化的外部硬盘上。可以恢复已删除的文件。当文件被删除时,文件名被标记为已删除,数据区域被标记为未分配/空闲,但 TestDisk 可…

    2024年1月5日
    14900
  • 使用jenkins 打包前端私服代码失败的问题

    问题现象: jinekins 流水线在yarn 编译前端私服依赖包的时候,报错,提示 Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password). 【emm。。。之前的构建都是好好的,也不知道前端大哥啥时候去封装的前端代码,而且奇怪的是没有放在公共库里。。。。】 Pipeline 流…

    2023年1月31日
    23100
  • Linux/windows禁止ping和取消禁止ping的方法

    LINUX: Linux默认是允许Ping响应的,系统是否允许Ping由内核参数决定。 具体的配置方法如下: 内核参数设置 1、允许PING设置 1)临时允许PING操作的命令为: #echo 0 >/proc/sys/net/ipv4/icmp_echo_ignore_all 2)永久允许PING配置方法 /etc/sysctl.conf中增加一行 …

    2022年6月13日
    1.7K00

发表回复

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

在线咨询: QQ交谈

邮件:712342017@qq.com

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

关注微信