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

相关推荐

  • CentOS 修改 SSH无操作自动断开时长及连接超时

    CentOS 修改 SSH无操作自动断开时长 当 SSH 连接到 CentOS 服务器时, 如果一段时间不操作, SSH 会自动断开。 这时, 可修改配置增加连接时长。 一、修改配置 在配置中找到 修改为 ClientAliveInterval 指定了服务器端向客户端发送消息的间隔,默认 0 不发送消息。ClientAliveInterval 30…

    2023年2月20日
    1.9K00
  • k8s-重启Pod方法

    kubectl 没有 restart pod 这个命令,主要是由于在 k8s 中pod 的管理属于rs 等控制器,并不需要手动维护,但有时更新了yaml文件后,期望破都能够”重启”重新加载yaml文件,比如修改了configmap 的配置文件后,希望重启pod 加载配置,此时就需要 “重启” Pod。而”重启”…

    2023年10月9日
    1.2K00
  • 微信扫码登录的技术实现思考

    简介: 微信扫码登录是很常见的技术,曾经在一次面试当中,面试官就曾问过微信扫码登录的实现思路,这次,以微信读书网页版扫码登录为例子,聊聊我对它技术实现思路一些思考。 微信扫码登录是很常见的技术,曾经在一次面试当中,面试官就曾问过微信扫码登录的实现思路,这次,以微信读书网页版扫码登录为例子,聊聊我对它技术实现思路一些思考。 以谷歌浏览器来做分析,打开F12,准…

    2023年11月10日
    95100
  • CentOS安装noVNC,以Web方式交付VNC远程连接

    什么是noVNC noVNC 是一个 HTML5 VNC 客户端,采用 HTML 5 WebSockets, Canvas 和 JavaScript 实现,noVNC 被普遍用在各大云计算、虚拟机控制面板中,比如 OpenStack Dashboard 和 OpenNebula Sunstone 都用的是 noVNC。 noVNC 采用 WebSockets…

    2024年5月8日
    96100
  • Linux安装青龙面板 稳定版超级详细

    一.安装docker容器 1.工具安装 复制所有代码然后直接右键粘贴进去 中间过程输入y 回车 yum install docker-io –y 这里输入y 安装成功之后是这个样子 输入以下代码回车 systemctl start docker 复制粘贴下面命令回车 docker ps 如果显示下图 即为成功 二.安装青龙面板 1.安装面板 (想改青龙面板端…

    2022年6月22日
    3.0K00

发表回复

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

在线咨询: QQ交谈

邮件:712342017@qq.com

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

关注微信