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 7下安装配置Tomcat

    CentOS 7下安装配置Tomcat 环境:CentOS 7.9 Tomcat下载地址:http://down.cnaaa.net/static/upload/other/20220802/1659432295529455.rar 安装rz工具 创建Tomcat目录 通用rz工具,将安装包上传 解压文件 修改目录名Tomcat8 没有JDK安装JDK 目录…

    2022年8月2日
    53300
  • Linux 大日志文件按时间查询与分割处理

    按时间查看日志 日志文件有40G: 大文件分割 split命令操作 按文件行数分割 catalina.out 按50000分割一个文件: 按文件大小分割 除了按照行数切割之外,split还支持通过文件大小进行切割,通过指定-b参数指定文件大小进行切割,文件大小单位支持K, M, G, T, P, E, Z,如下以切割为500M演示文件切割过程。

    2024年1月9日
    23300
  • 在Linux中执行yum命令失败,提示“HTTP Error 404 -Not Found Trying other mirror”错误怎么办?

    问题描述 在Linux系统的ECS实例中执行yum命令(如yum -y install XXX、yum list、yum search XXX等)失败,出现类似如下错误信息。 问题原因 出现该问题可能有以下原因: 解决方案 切换CentOS 6/8的源地址 CentOS 6与CentOS 8操作系统版本结束了生命周期(EOL),Linux社区已不再维护该操作…

    2023年11月28日
    18300
  • nmcli命令详解

    以下是nmcli命令的一些常用选项和用法: 1)修改网卡名称 2)添加网卡 3)启动或停止网卡 4)设置网卡获取IP模式 使用 nmcli 来设置网卡为静态IP ,可以使用以下命令: 使用nmcli命令将网卡eth0模式设置为dhcp

    2023年10月10日
    42200
  • NetSet – 自动化网络流量安全增强工具

    NetSet旨在自动执行多个操作,以帮助用户保护网络流量。它还提供了一种通过Tor收集代理和运行实用程序的简便方法。NetSet安装和使用的也是自动配置,该工具主要用于辅助性网络安全任务。 实现了一种按需使用的终端多路复用器,它的会话通过Tor路由网关。通过自动安装和配置DNSCrypt-proxy来保护DNS流量。Tor Wall功能强制所有流量通过Tor…

    2023年10月8日
    35500

发表回复

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

在线咨询: QQ交谈

邮件:712342017@qq.com

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

关注微信