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

相关推荐

  • Linux实验案例:构建DHCP服务器

    公司要求将闲置的一台Linux主机配置为DHCP服务器,以便为局域网内员工的办公用机提供自动分配IP地址服务,提高网络管理和维护的效率。 需求描述 给局域网内各主机自动分配的IP地址范围为192.168.10.20~192.168.10.30 局域网内各主机使用的默认网关地址为192.168.10.2 局域网内各主机使用的DNS服务器地址分别为202.96.…

    2024年6月24日
    1.6K00
  • Docker常用命令

    列出所有容器ID 查看所有运行或者不运行容器 停止所有的container(容器),这样才能够删除其中的images: 如果想要删除所有container(容器)的话再加一个指令: 查看当前有些什么images 删除images(镜像),通过image的id来指定删除谁 想要删除untagged images,也就是那些id为的image的话可以用 要删除全…

    2022年11月19日
    1.1K00
  • Windows下安装Nginx错误总结

    别问我为啥非要在Windows上按照Nginx,问的话,回答就是:有这个需求 1:CreateFile()“xxxxx” failed (3: The system cannot find the path specified) 产生原因:创建文件xxxx异常了。大多数情况就是因为:安装目录中存在中文或者是空格 比如凯哥的就是因为存在空格。凯哥第一…

    2024年5月11日
    96900
  • 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日
    1.3K00
  • ansible 用普通用户sudo 执行命令

    背景: linux 机器都禁止root用户远程直接登录,需要ansible切换用户来实现 配置 /etc/ansible/hosts [test] 192.168.55.65 ansible_ssh_user=vmuser ansible_ssh_pass=’112233′ ansible_become_pass=’778899′ 192.168.55.66…

    Linux系统 2023年2月6日
    1.4K00

发表回复

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

在线咨询: QQ交谈

邮件:712342017@qq.com

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

关注微信