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

相关推荐

  • 安装 Smem – Linux工具 安装条件: 现代内核 (版本号高于 2.6.27) 较新的 Python 版本 (2.4 及以后版本) 可选的 matplotlib 库用于生成图表 对于当今的大多数的 Linux 发行版而言,内核版本和 Python 的版本都能够满足需要,所以仅需要为生成良好的图表安装 matplotlib 库。 RHEL,…

    2023年8月25日
    1.4K00
  • Linux 从 lsof 开始,深入理解 Linux 虚拟文件系统!

    背景 有时会出现这样的情况,磁盘空间显示已经被占满,但是在查看磁盘的具体文件占用情况时,发现磁盘仍然有很大的空余空间。 1. 执行df命令查看磁盘使用情况,发现磁盘已经满了。 2. 执行du命令查看各个目录的磁盘占用情况,把各个目录文件的大小相加,发现并没有占满磁盘,有10多G空间莫名失踪。 3. 为何会出现这样的情况呢? 因为虽然文件已被删除,但是一些进程…

    2024年2月20日
    1.4K00
  • Centos7中搭建WebDav的服务

    一 什么是WebDAV 百度百科的定义:WebDAV (Web-based Distributed Authoring and Versioning) 一种基于 HTTP 1.1协议的通信协议。它扩展了HTTP 1.1,在GET、POST、HEAD等几个HTTP标准方法以外添加了一些新的方法,使应用程序Web Server直接读写,并支持写文件锁定(Lock…

    2023年3月9日
    1.4K00
  • linux 文件挂载配置错误解决办法

    linux中挂载命令经常能够用到,特别是配置开机自动挂载的时候,一不留神就配置错误了,这样造成的后果就是重启过后就会发现系统起不来了!!! 首先进行模拟测试 格式化磁盘 mkfs.ext4 /dev/sdb1 挂载磁盘 mount /dev/sdb1 /mnt 修改配置文件并进行破环 vi /etc/fstab 重启验证后发现不能远程登录,系统进入救援模式!…

    2023年9月27日
    1.3K00
  • 服务器卡死,重启报错: INFO: task blocked for more than 120 seconds

    问题:服务器负载很高,但是CPU利用率不高。服务器经常夯住,网站打不开,SSH连接非常不稳定,输入命令夯住。 重启服务器报错: INFO: task blocked for more than 120 seconds 问题原因:  默认情况下, Linux会最多使用40%的可用内存作为文件系统缓存。当超过这个阈值后,文件系统会把将缓存中的内存全部写…

    2023年3月27日
    1.6K00

发表回复

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

在线咨询: QQ交谈

邮件:712342017@qq.com

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

关注微信