• Linux CentOS 8(HTTPS的配置与管理)



    Linux CentOS 8(HTTPS的配置与管理)



    一、HTTPS 介绍

    HTTPS 在 HTTP 的基础下加入 SSL,SSL 是“Secure Sockets Layer”的缩写,中文为“安全套接层”。因此 HTTPS 是以安全为目标的 HTTP 通道,在 HTTP 的基础上通过传输加密和身份认证保证了传输过程的安全性。 因此 SSL 证书的两大作用是数据加密和身份认证。

    二、SSL 证书的介绍

    SSL 证书遵循 SSL 协议,通过在客户端浏览器和 Web 服务器之间建立一条 SSL 安全通道。一个有效、可信的 SSL 数字证书包括一个公共密钥和一个私用密钥。公共密钥用于加密信息,私用密钥用于解译加密的信息。因此,客户机浏览器指向一个安全域时,SSL 将同步确认服务器和客户端,并创建一种加密方式和一个唯一的会话密钥。它们可以启动一个保证消息的隐私性和完整性的安全会话。

    三、实验配置

    1、安装 openssl 软件包

    [root@www test]# yum -y install openssl
    
    • 1

    2、查看openssl.cnf文件,如图1-1所示。

    [root@www ~]# vim /etc/pki/tls/openssl.cnf
    
    • 1

    在这里插入图片描述

    图1-1

    3、创建index.txtserial文件

    [root@www ~]# ls /etc/pki/tls/
    
    
    CA  ct_log_list.cnf  misc  openssl.cnf  certs   newcerts  private  
    [root@www ~]# touch /etc/pki/tls/index.txt
    [root@www ~]# echo 01 > /etc/pki/tls/serial
    [root@www ~]# ls /etc/pki/tls/
    CA  ct_log_list.cnf  misc  openssl.cnf  serial certs index.txt  newcerts  private 
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    4、安装mod_ssl模块

    [root@www ~]# yum -y install mod_ssl
    [root@www ~]# ls /etc/httpd/conf.d/
    autoindex.conf  htpasswd  httpd-vhosts.conf  README  ssl.conf  userdir.conf  welcome.conf
    //生成了ssl.conf配置文件
    
    • 1
    • 2
    • 3
    • 4

    5、修改ssl.conf文件

    [root@www ~]# vim /etc/httpd/conf.d/ssl.conf
    DocumentRoot "/var/www/html"                       
    //访问的目录路径
    SSLCertificateFile /etc/httpd/ssl/server.crt           
    //证书的路径
    SSLCertificateKeyFile /etc/httpd/ssl/server.key
    //证书私钥文件的路径
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    6、生成证书
    创建并切换到指定目录下(ssl.conf文件中证书所在位置)

    [root@www ssl]# cd /etc/httpd/ssl
    
    • 1

    创建私钥文件

    [root@www ssl]# openssl genrsa -des3 -out server.key 2048
    Generating RSA private key, 2048 bit long modulus (2 primes)
    ...................................................................................................................................
    ...................................................................................................................................
    e is 65537 (0x010001)
    Enter pass phrase for server.key:
    Verifying - Enter pass phrase for server.key:
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    创建证书签署请求

    [root@www ssl]# openssl req -new -key server.key -out server.csr
    Enter pass phrase for server.key:
    You are about to be asked to enter information that will be incorporated
    into your certificate request.
    What you are about to enter is what is called a Distinguished Name or a DN.
    There are quite a few fields but you can leave some blank
    For some fields there will be a default value,
    If you enter '.', the field will be left blank.
    -----
    Country Name (2 letter code) [XX]:CN
    State or Province Name (full name) []:GD
    Locality Name (eg, city) [Default City]:GZ
    Organization Name (eg, company) [Default Company Ltd]:Jan16
    Organizational Unit Name (eg, section) []:Technology
    Common Name (eg, your name or your server's hostname) []:www.example.com
    Email Address []:www.jan16.com
    Please enter the following 'extra' attributes
    to be sent with your certificate request
    A challenge password []:jan16
    An optional company name []:jan16
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20

    创建自签证书

    [root@www ssl]# openssl req -new -x509 -key server.key -out ca.crt -days 3650
    Enter pass phrase for server.key:
    You are about to be asked to enter information that will be incorporated
    into your certificate request.
    What you are about to enter is what is called a Distinguished Name or a DN.
    There are quite a few fields but you can leave some blank
    For some fields there will be a default value,
    If you enter '.', the field will be left blank.
    -----
    Country Name (2 letter code) [XX]:CN
    State or Province Name (full name) []:GD
    Locality Name (eg, city) [Default City]:GZ
    Organization Name (eg, company) [Default Company Ltd]:Jan16
    Organizational Unit Name (eg, section) []:Technology
    Common Name (eg, your name or your server's hostname) []:www.example.com
    Email Address []:www.jan16.com 
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16

    签发证书

    [root@www ssl]# openssl x509 -req -days 3650 -in server.csr -CA ca.crt -CAkey server.key -CAcreateserial -out server.crt
    Signature ok
    subject=C = cn, ST = gz, L = th, O = jan16, OU = t, CN = www.example.com, emailAddress = 11.com
    Getting CA Private Key
    Enter pass phrase for server.key:
    
    • 1
    • 2
    • 3
    • 4
    • 5

    7、重启服务

    [root@www ssl]# systemctl restart httpd
    Enter TLS private key passphrase for www.example.com:443 (RSA) : **********
    
    • 1
    • 2

    8、验证

    [root@www httpd]# cat /var/www/html/index.html
    This is my website!!
    
    • 1
    • 2

    显示当前网站不安全,如图2-1所示。
    在这里插入图片描述

    图2-1

    点击设置中的【首选项】,导入证书,如图2-2所示。
    在这里插入图片描述

    图2-2

    点击【隐私与安全】,查看证书,如图2-3所示。
    在这里插入图片描述

    图2-3

    点击导入,如图2-4所示。
    在这里插入图片描述

    图2-4

    切换到对应的目录,选择ca.crt 证书,如图2-5所示。
    在这里插入图片描述

    图2-5

    勾选【信任由此证书颁发机构来标识网址】和【信任由此证书颁发机构来标识电子邮件用户】两个选项,点击【确定】,如图2-6所示。
    在这里插入图片描述

    图2-6

    刷新网站,能成功访问,如图2-7所示。
    在这里插入图片描述

    图2-7

    制作成员: 何嘉愉
    排版: 裕新
    初审: 杨佳佳
    复审: 二月二

  • 相关阅读:
    K8s云原生存储Rook详解
    标准化学校考场自动校时同步时钟系统
    基于JAVA-物料采购合同管理系统-计算机毕业设计源码+系统+mysql数据库+lw文档+部署
    XSS进阶之CSP绕过
    centos虚拟机无法接受消息(防火墙)
    日志11.7学习Http请求响应协议及语法、编写接口测试
    1130 - Host ‘192.168.10.10‘ is not allowed to connect to this MysOL server
    资源描述框架的用途及实际应用解析
    ROS参数名称设置
    OSINT技术情报精选·2024年6月第2周
  • 原文地址:https://blog.csdn.net/hjx020/article/details/125060919