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 SSH 登录失败多少次禁止该IP访问 防止暴力破解

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

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

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

    2023年4月11日
    10000
  • Ubuntu系统如何配置镜像源

    我们在使用Linux系统时,一般来说都是需要配置一个源地址才能直接使用下载的命令来安装软件的,若你购买的是云服务器,正常来讲是服务器厂商配置好了源的,但是也不缺乏有少量的机器源会出现问题,导致安装软件不成功,如下图所示,那么我们就需要手动去配置了 第一步:替换原有的源 第二步:安装证书 如果安装失败,重新安装即可

    2022年6月14日
    55600
  • 部署linux服务器管理面板–Ajenti

    一、部署Ajenti服务器管理面板 1.Ajenti官网 官网地址:https://ajenti.org/ 2.其他操作系统部署方式 3.部署Ajenti 在本地直接部署署Ajenti,安装成功会有如下提示。 curl https://raw.githubusercontent.com/Eugeny/ajenti/master/scripts/install…

    2023年9月19日
    2800
  • 通过 Linux 命令行连接远程 Windows 系统

    安装 xfreerdp 在使用 xfreerdp 之前,您需要安装它。在大多数 Linux 发行版中,您可以使用包管理器来执行此操作。 在 Ubuntu / Debian 和 Linux Mint 上,运行以下命令 基于 RHEL 的发行版,如 Rocky Linux、AlmaLinux 和 Fedora,运行以下命令 使用 xfreerdp 远程连接 Wi…

    2023年9月20日
    2300

发表回复

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

在线咨询: QQ交谈

邮件:712342017@qq.com

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

关注微信