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

相关推荐

  • Centos7下离线安装mysql8.0.20

    一、下载linux mysql8.0 离线安装包 首先去mysql官网下载mysql的离线rpm安装包(https://downloads.mysql.com/archives/community/) 二、安装mysql 1、由于mariadb中的lib包和mysql8.0.20的lib包冲突,如果已经安装了mariadb,则需要将其卸载。 2、卸载mari…

    2022年12月5日
    2.1K00
  • Ubuntu防火墙使用方法

    安装防火墙 ufw防火墙开启和关闭 修改ufw防火墙规则 ufw命令使用实例

    2022年12月3日
    1.5K00
  • ubuntu修改默认文件权限umask

    在Ubuntu中,umask是一个内置的shell命令,用于确定新创建文件和目录的默认权限。umask值是一个三位或四位的八进制数。这个值被从全权限(即777)中减去,以得到新文件或目录的默认权限。 要临时修改umask值,你可以在命令行中直接输入umask命令,后面跟上你想要的值。例如,要将umask设置为022(这将使新文件的默认权限为755,新目录的默…

    2023年10月16日
    1.9K00
  • 使用 B VPS 中转 A VPS 流量

    引言 由于某些不可抗力原因, 所处网络环境无法访问 A VPS, 因此 增加 能访问到的 B VPS 来中转流量到 A VPS me –x-> A VPS me <—-> B VPS <—-> A VPS 非内网穿透需求, A VPS 有公网ip, 可被公网直接发现 和使用某些客户端 配合 Cloudflare…

    2024年6月28日
    3.1K00
  • OpenSuSe系统登录密码忘了如何进行重置

    如果你的OpenSusE系统密码忘记了,又不想重装系统,那么,你可以通过如下几个步骤来强制重置root密码 1、重新启动机器,在出现grub引导界面后,按“e”,出现启动Linux的选项,移动光标至第一个选项上再次按“e”出现一个编辑字符的界面在字符后面加入“init=/bin/bash”字段,然后回车。按Ctrl+X,通过给内核传递init=/bin/ba…

    2022年11月24日
    2.0K00

发表回复

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

在线咨询: QQ交谈

邮件:712342017@qq.com

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

关注微信