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/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日
    3.1K00
  • 轻松搭建DHCP服务器

    DHCP(Dynamic Host Configuration Protocol)动态主机配置协议 DHCP(Dynamic Host Configuration Protocol),动态主机配置协议,是一个应用层协议。当我们将客户主机ip地址设置为动态获取方式时,DHCP服务器就会根据DHCP协议给客户端分配IP,使得客户机能够利用这个IP上网。DHCP的…

    2023年12月6日
    97500
  • grafana 钉钉报警设置

    一、钉钉机器人创建与配置 1.创建钉钉群&钉钉机器人 2.创建一个自定义机器人,在“机器人设置”中获得webhook的URL 3.安全设置,这一步是必须的,我选择白名单模式,填入grafana服务器地址 二、grafana设置警报 1.在grafana控制台,左边栏“Alerting”模块,创建一个警报。 2.可点击test发送测试警报 三、钉钉警报…

    2024年5月15日
    1.8K00
  • centos7下smartctl安装配置

    安装 使用

    2023年4月13日
    1.6K00
  • Ubuntu 启用root账户并开启远程登录

    1.启用root账户 修改root用户密码,输入下方命令后,还需要输入当前普通用户的密码进行身份验证,然后修改root用户的新密码 sudo passwd root 2、开启远程登录 执行下方命令后开启root用户的远程登录 此时就能使用root账户成功登录了

    2022年6月11日
    1.8K00

发表回复

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

在线咨询: QQ交谈

邮件:712342017@qq.com

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

关注微信