• 在 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指南。

  • 相关阅读:
    arcgis--二维点、线转三维
    PHP项目学习笔记-萤火商城-增加一个模块(表涉及到的操作和文件)
    《虹口区促进元宇宙产业发展的试行办法》的通知
    app测试定位方式
    初识Java 17-4 反射
    MySQL(二)SQL分类和语言规范
    【算法】快速排序 详解
    【JavaEE】JavaScript webAPI的基本知识
    Open3D 点云区域生长分割算法
    R语言基于with函数对指定的协变量执行双样本t检验、t.test函数对不同分组对应的协变量的均值进行Welch双样本t检验分析、双独立样本t检验
  • 原文地址:https://blog.csdn.net/allway2/article/details/126265716