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

相关推荐

  • Ubuntu修改静态IP、网关和DNS的方法总结

    /etc/netplan (use) Ubuntu 18.04开始可以使用netplan配置网络,其也是默认安装的。配置文件位于/etc/netplan/xxx.yaml中,netplan默认是使用NetworkManager来配置网卡信息的。 使用 netplan apply 网络配置 Ubuntu /etc/network/interfaces 修改静态…

    2023年11月27日
    1.4K00
  • 多台服务器如何设置SSH免密登录

    本次测试需要服务器己安装好 ssh-keygen和ssh-copy-id。安装方式如下: 安装ssh-keygen和ssh-copy-id 1、在客户端机器上生成密钥,这里连续三个回车默认即可。 3、进入到/root/.ssh/目录下,查看是否生成密钥成功,这里一共生成三个文件,本次主要用到的是id_rsa.pub:私钥(本次实验用到的) 4、通过命令复制私…

    2022年6月16日
    1.8K00
  • Linux——手把手教你解决sudo指令无法使用的问题

    解决sudo指令无法使用的问题 1. 为什么不能使用 sudo指令能够使某一条指令拥有root权限,即以root权限去执行 例如 sudo ls -l 但是,如果是新创建的普通账户,一般来说一开始是不能执行sudo命令的: 根据提示,LQF这一用户并不在sudoers这个文件中,因此没有使用sudo的权利suduers文件位于路径/etc/sudoerssu…

    2024年5月31日
    1.6K00
  • Centos系统下RabbitMQ安装教程

    一、前言 RabbitMQ是一个开源的遵循 AMQP协议实现的基于 Erlang语言编写,即需要先安装部署Erlang环境再安装RabbitMQ环境。需加注意的是,读者若不想跟着我的版本号下载安装,可根据两者版本号的对应表(下面图示只展示了部分),安装相应版本的Erlang和RabbitMQ,只需在下文修改命令里面的版本号即可。 二、Erlang下载安装 在…

    2022年6月16日
    1.8K00
  • Linux系统之nethogs命令

    1.简介 NetHogs是一个小型的net top工具,不像大多数工具那样拖慢每个协议或者是每个子网的速度而是依照进程进行带宽分组。 NetHogs不需要依赖载入某个特殊的内核模块。 假如发生了网络堵塞你能够使用NetHogs立即看到哪个PID形成的这种情况。 这样就很容易找出哪个程序突然长时间占用你的带宽。 NetHogs是一个类似于Linux的top指令…

    2023年9月19日
    1.3K00

发表回复

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

在线咨询: QQ交谈

邮件:712342017@qq.com

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

关注微信