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

相关推荐

  • Windows配置磁盘监控

    通过pushgateway的方式,主动推送监控数据给prometheus。 由于windows平台的诸多限制,导致推送比较艰难。有两种方法完成监控。 1.通过python等语言,做推送脚本。 2.曲线救国就是把监控数据scp发给Linux机器。再通过linux做二次加工推给pushgateway。 window server上配置环境 1.首先判断服务器磁盘…

    2022年11月25日
    1.0K00
  • Centos7忘记root密码怎么办

    重启linux,进入系统的GRUB菜单界面,选择最下方的,按下小写字母e进入编辑界面 按下方向键,找到以字符串Linux16开头的行,光标移动到结尾,然后输入init=/bin/bash enforcing=0 代表登录系统后,加载bash解释器,然后关闭selinux 按下ctrl+x组合键以单用户模式启动Linux 输入如下命令,重新挂载根目录,进入可写…

    2022年6月11日
    1.2K00
  • Linux SSH 登录失败多少次禁止该IP访问 防止暴力破解

    Linux 系统SSH 登录失败的内容会记录到/var/log/secure文件,通过查找关键字 Failed,可以定位到这些异常的IP地址,比如: 比如这里,明显这个IP地址在进行SSH 扫描,不断的更换端口和用户进行暴力测试。 在Linux里面有两个相关的文件: /etc/hosts.allow: 允许哪些IP访问主机 /etc/hosts.deny 禁…

    2023年3月1日
    1.2K00
  • 关于磁盘IO的那些事

    关于磁盘IO的那些事 一、背景 需要把生产上一份clickhouse的备份数据到测试环境上,心想也就59G 的大小,应该很快吧,殊不知压缩就搞了3个多小时,于是好奇看下磁盘IO的一些参数,分享给大家学习参考 在分析存储性能之前,需要先了解存储性能定义的三个核心指标:IOPS、Throughput、await 指标 说明 IOPS 每秒进行的IO操作次数 Th…

    2023年4月11日
    98100
  • 如何处理CentOS Failed to load SELinux policy

    CentOS 7在启动时,卡在进度条界面一直进不去系统,如下图所示: 我们可以通过按键盘的左右方向键,可以看到提示“Failed to load SELinux policy.”,这就是造成系统一直卡住无法正常启动的原因。 原因 是因为没有正确修改系统的selinux的配置,导致系统在启动时报selinux的错误 解决方案 第一步:先重启CentOS7操作系…

    2022年6月15日
    1.5K00

发表回复

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

在线咨询: QQ交谈

邮件:712342017@qq.com

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

关注微信