• 在 CentOS 8 上为Apache HTTPD 配置 HTTPS


    本文假设您已经在 RHEL 8/CentOS 8 服务器上执行了 Apache 网络服务器的基本安装和配置

    1. 安装mod_ssl模块。第一步是使用dnf命令安装mod_ssl模块:
      # dnf install mod_ssl
      
    2. 启用mod_ssl模块。如果您刚刚安装mod_ssl,该模块可能尚未启用。要测试是否mod_ssl启用执行:
      1. # apachectl -M | grep ssl
      2. # httpd -M

      如果您没有看到上述命令的输出,则您mod_ssl未启用。要启用该mod_ssl模块,请重新启动您的Apache httpd网络服务器:

      1. # systemctl restart httpd
      2. # apachectl -M | grep ssl
      3. # httpd -M
      4. ssl_module (shared)

    3. 打开 TCP 端口 443以允许使用https协议的传入流量:
      1. # firewall-cmd --zone=public --permanent --add-service=https
      2. success
      3. # firewall-cmd --reload
      4. success

      注意
      此时您应该能够通过 HTTPS 协议访问您的 Apache 网络服务器。浏览您的浏览器https://your-server-iphttps://your-server-hostname确认mod_ssl配置。

    4. 生成 SSL 证书。如果您的服务器还没有正确的 SSL 证书,请使用以下命令生成新的自签名证书。

      例如,让我们为主机生成一个新的自签名证书,rhel8有效期为 9999天:

      1. openssl req -newkey rsa:4096 -nodes -keyout /etc/pki/tls/private/localhost.key -x509 -days 9999 -out /etc/pki/tls/certs/localhost.crt
      2. ..+......+....+..+.........+......+....+.........+.....+...+..........+..+.......+...+.....+.+...........+.+.....+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*..+.+........+.+.....+....+..+...............+.+........+....+...+..+.......+.....+....+.........+........+.........+......+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*.....+.........+...+.........+.+............+......+..+...+..........+..+....+...+............+........+.+..+...+...............+.......+........+................+...........+...+....+...............+...........+................+...+.....+................+..+....+...+.....+...+.......+..+....+.........+......+...........+......+...+.........+.+...............+......+.........+.........+..+.+.....+...+....+..+.+...............+.........+..................+...+.....+.......+..+...+......+.........+..................+...+..........+..........................+......+..........+........+....+..+...+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
      3. ..+............+................+..+...+.....................+..........+........+.......+......+..+.+...........+.........+....+..+.+..+...+..........+..............+...+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*..+.....+...+...+.+.....+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*...+................+.....+.+.................+.......+...+........+...+.........+.........................+.....+...+....+...+..+....+.....+...............+....+...........+.+...+........+...+......+....+...............+..............+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
      4. -----
      5. You are about to be asked to enter information that will be incorporated
      6. into your certificate request.
      7. What you are about to enter is what is called a Distinguished Name or a DN.
      8. There are quite a few fields but you can leave some blank
      9. For some fields there will be a default value,
      10. If you enter '.', the field will be left blank.
      11. -----
      12. Country Name (2 letter code) [XX]:
      13. State or Province Name (full name) []:
      14. Locality Name (eg, city) [Default City]:
      15. Organization Name (eg, company) [Default Company Ltd]:
      16. Organizational Unit Name (eg, section) []:
      17. Common Name (eg, your name or your server's hostname) []:
      18. Email Address []:

      成功执行上述命令后,将创建以下两个 SSL 文件:

      1. # ls -l /etc/pki/tls/private/localhost.key /etc/pki/tls/certs/localhost.crt
      2. -rw-r--r--. 1 root root 1931 810 14:27 /etc/pki/tls/certs/localhost.crt
      3. -rw-------. 1 root root 3272 810 14:27 /etc/pki/tls/private/localhost.key

    5. 使用新的 SSL 证书配置 Apache Web 服务器。要将新创建的 SSL 证书包含到 Apache Web 服务器配置中,请/etc/httpd/conf.d/ssl.conf使用管理权限打开文件并更改以下行(如果文件名未使用localhost):
      1. FROM:
      2. SSLCertificateFile /etc/pki/tls/certs/localhost.crt
      3. SSLCertificateKeyFile /etc/pki/tls/private/localhost.key
      4. TO:
      5. SSLCertificateFile /etc/pki/tls/certs/httpd.crt
      6. SSLCertificateKeyFile /etc/pki/tls/private/httpd.key

      一旦准备好重新加载Apache httpd网络服务器:

      # systemctl reload httpd

    6. 通过将 Web 浏览器URL导航到https://your-server-iphttps://your-server-hostname来测试您的mod_ssl配置。
    7. 作为可选步骤,将所有 HTTP 流量重定向到 HTTPS.T,创建一个/etc/httpd/conf.d/redirect_http.conf包含以下内容的新文件:
      1. <VirtualHost _default_:80>
      2. Servername rhel8
      3. Redirect permanent / https://rhel8/
      4. VirtualHost>
      要应用更改重新加载 httpd守护程序:
      # systemctl reload httpd

      上述配置会将任何传入流量重定向http://rhel8https://rhel8URL。有关 RHEL Linux 服务器上的 TLS/SSL 配置的更多信息,请访问我们的如何在 Red Hat 上使用 Apache httpd 设置 SSL/TLS指南。

  • 相关阅读:
    【深度学习驱动流体力学】完整配置安装 OpenFOAM 及其所需的ThirdParty与QT5工具
    从 NASL 说开:低代码编程语言能饭否
    Java刷题面试系列习题(七)
    淘宝商家私信脚本,自动批量阿里旺旺版,按键精灵源码分享
    Qt+Opencv+Ffmpeg实时摄像头数据推流,并在WEB端显示
    MD5 绕过第二式:数组绕过
    【演讲干货满满】共话数智转型之路:斯歌应邀出席2023德莱维数字技术行业峰会
    生成音频二维码:点燃听觉体验的魔法之门
    第三篇 《随机点名答题系统》——人员管理详解(类抽奖系统、在线答题系统、线上答题系统、在线点名系统、线上点名系统、在线考试系统、线上考试系统)
    React学习总结
  • 原文地址:https://blog.csdn.net/allway2/article/details/126265716