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

相关推荐

  • Prometheus 监控进程

    prometheus 进程的监控 1. process exporter功能 2. 监控目标对主机进程的监控,chronyd sshd 等服务进程已经已定义脚本运行程序的运行状态监控。 process-compose的安装 监控所有进程 监控指定进程 docker 运行 docker ps -a 确认 up http://10.19.1.220:9256/m…

    2024年1月4日
    1.2K00
  • Linux系统管理本地 Linux 用户和组

    Linux的用户UID 系统中的每个进程(运行程序)都作为一个特定用户运行。每个文件归一个特定用户所有。对文件和目录的访问受到用户的限制。与运行进程相关联的用户可确定该进程可访问的文件和目录。 用户的分类 root用户 用户系统中唯一,权限最大,可以操作任意命令 普通用户 权限较低,只能编辑自己的用户家目录,由root账户创建 虚拟用户 没有登录系统的权限,…

    2022年6月11日
    1.6K00
  • 迁移到新服务器上的PHP网站,使用浏览器访问时提示“不支持MySQL”等信息,如何处理?

    问题描述 PHP网站(该网站需使用PHP执行程序代码)迁移到新服务器后,在使用浏览器访问时提示如下任意一种信息。 问题原因 因为MySQL扩展功能自PHP 5.5.0版本开始被废弃,并且从PHP 7.0.0版本开始被移除,当网站迁移到新服务器时一般会迁移到PHP 7.0.0及以上版本,由于网站迁移后的新服务器的PHP版本过高,网站程序无法再连接MySQL,导…

    2023年11月17日
    1.4K00
  • Docker部署MinIO对象存储服务器结合Cpolar实现远程访问

    前言MinIO是一个开源的对象存储服务器,可以在各种环境中运行,例如本地、Docker容器、Kubernetes集群等。它兼容Amazon S3 API,因此可以与现有的S3工具和库无缝集成。MinIO的设计目标是高性能、高可用性和可扩展性。它可以在分布式模式下运行,以满足不同规模的存储需求。 MinIO是一个开源的软件,可以免费使用,还可以在普通硬件上运行…

    2023年12月20日
    1.3K00
  • 轻松掌握组件启动之Redis单机、主从、哨兵、集群配置

    Redis安装 下载地址:http://redis.io/download 安装步骤: 1: 安装gcc编译器:yum install gcc 2: 将下载好的redis‐5.0.3.tar.gz文件放置在/usr/local文件夹下,并解压redis‐5.0.3.tar.gz文件 3: 切换到解压后的redis‐5.0.3目录下,完成编译与安装 4: 修改…

    2024年5月11日
    1.3K00

发表回复

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

在线咨询: QQ交谈

邮件:712342017@qq.com

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

关注微信