HTTPS服务

一、常见的端口

http ------ 80 明文

https ------ 443 数据加密

dns ------ 53

ssh ------ 22

telent ------ 23

HTTPS = http + ssl或者tls (安全模式)

二、原理:

c(客户端):
1、clienthello:支持哪些版本、支持哪些加密算法,随机生成一组32字节数据random_c
3、clientkeyexchange:公钥加密数据pre_master

s(服务器):
2、serverhello:确定版本、确定加密算法,随机生成一组32个字节得数据random_s,生成公钥和私钥
servercertificate:证书、公钥
4、data:服务端收到pre_master—私钥进行解密
最后得会话密钥:random_c+random_s+pre_master

三、实现安全------认证/鉴权

1、CA机构:认证某网站是安全的,给服务器的证书进行授权(相当于中介)

[root@stw ~]# vim /etc/pki/tls/openssl.cnf

dir = /etc/pki/CA(默认的CA的工作目录)

certs = $dir/certs(/etc/pki/CA/certs,证书所在的目录)

database = $dir/index.txt(/etc/pki/CA/index.txt,数据库位置,现在没有,需要生成)

certificate = $dir/cacert.pem(/etc/pki/CA/cacert.pem,CA的根证书,目前没有,需要生成)

serial = $dir/serial( /etc/pki/CA/serial,序列号,目前不存在)

private_key = $dir/private/cakey.pem(私钥,目前不存在,需要生成)

在这里插入图片描述

四、配置https服务

openssl: 命令的选项
-x509 :生成自签名证书格式,专用于创建私有CA
-new :生成新证书的签署请求
-key :生成请求时用到的私钥文件路径
-out :生成后的文件存放路径,如果是自签名操作,将直接生成签署过的证书
-days :证书有效期 默认是365天

CA服务器:
1、生成私钥
前提:在DNS服务器上的正向解析数据库中添加ca.example.com的解析内容
[root@stw ~]# cd /var/named
[root@stw named]# vim stw.com
[root@stw named]# systemctl restart named
[root@stw named]# systemctl enable named

在这里插入图片描述

在主机CA上为主机CA生成私钥

(umask 077;openssl genrsa -out /etc/pki/CA/private/cakey.pem)

root用户生成的文件默认的umask值是644,我们需要只让自己能读写此文件,所以需要umask值为600,所以应该设置umask值为066(文件的最大执行权限为666,666-066=600,目录的最大执行权限为777,777-077=700),对于文件来说给077和给066没有区别,都是只让自己读取此文件。

[root@stw ~]# (umask 077;openssl genrsa -out /etc//pki/CA/private/cakey.pem)
Generating RSA private key, 2048 bit long modulus
....................+++
...........................+++
e is 65537 (0x10001)
2、生成自签名证书
[root@stw ~]# openssl req -new -x509 -key /etc/pki/CA/private/cakey.pem -out /etc/pki/CA/cacert.pem -days 365
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) []:HB
Locality Name (eg, city) [Default City]:WH
Organization Name (eg, company) [Default Company Ltd]:LQ
Organizational Unit Name (eg, section) []:IT
Common Name (eg, your name or your server's hostname) []:ca.example.com
Email Address []:root@example.com
3、创建index.txt文件和serial文件
[root@stw ~]# cd /etc/pki/CA/
[root@stw CA]# ls
cacert.pem  certs  crl  newcerts  private
[root@stw CA]# touch index.txt
[root@stw CA]# echo 01 > serial     //序列号里面不能为空
[root@stw CA]# ls
cacert.pem  certs  crl  index.txt  newcerts  private  serial
Web(https)服务器:
1、关联DNS
[root@stw2 ~]# cd /etc/sysconfig/network-scripts/
[root@stw2 network-scripts]# vim ifcfg-ens33
[root@stw2 network-scripts]# systemctl restart network
[root@stw2 ~]# nslookup ca.example.com
Server:		192.168.100.10
Address:	192.168.100.10#53Name:	ca.example.com
Address: 192.168.100.10

在这里插入图片描述

2、生成私钥放在对应的位置
[root@stw2 ~]# cd /etc/httpd
[root@stw2 httpd]# ls
conf  conf.d  conf.modules.d  logs  modules  run
[root@stw2 httpd]# mkdir ssl
[root@stw2 httpd]# cd ssl
[root@stw2 ssl]# (umask 077;openssl genrsa -out /etc/httpd/ssl/httpd.key)
Generating RSA private key, 2048 bit long modulus
..............................................................+++
..........................................................+++
e is 65537 (0x10001)
3、生成自签名证书放在对应位置
[root@stw2 ssl]# openssl req -new -key /etc/httpd/ssl/httpd.key -out /etc/httpd/ssl/httpd.csr -days 365
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) []:HB
Locality Name (eg, city) [Default City]:WH
Organization Name (eg, company) [Default Company Ltd]:LQ
Organizational Unit Name (eg, section) []:IT
Common Name (eg, your name or your server's hostname) []:stw2.example.com
Email Address []:root@example.comPlease enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
[root@stw2 ssl]# 
4、把刚刚生成的证书发送给CA机构,让CA机构为Web服务器的证书进行签名
Web服务器:
[root@stw2 ssl]# scp httpd.csr root@ca.example.com:/etc/pki/CA
The authenticity of host 'ca.example.com (192.168.100.10)' can't be established.
ECDSA key fingerprint is SHA256:R7/1dpul7cu8SnefsN2wQw5hKDL+xekk0ffasLS6OGI.
ECDSA key fingerprint is MD5:81:88:a1:16:52:83:c0:d5:59:ad:2b:3a:d5:52:02:bc.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'ca.example.com,192.168.100.10' (ECDSA) to the list of known hosts.
root@ca.example.com's password: 
httpd.csr                                                                      100% 1033   339.7KB/s   00:00    
CA服务器查看:
[root@stw CA]# ls
cacert.pem  certs  crl  httpd.csr  index.txt  newcerts  private  serial
对Web服务器发送过来的证书进行认证授权
[root@stw CA]# openssl ca -in /etc/pki/CA/httpd.csr -out /etc/pki/CA/httpd.crt -days 365
Using configuration from /etc/pki/tls/openssl.cnf
Check that the request matches the signature
Signature ok
Certificate Details:Serial Number: 1 (0x1)ValidityNot Before: Aug 12 10:19:54 2025 GMTNot After : Aug 12 10:19:54 2026 GMTSubject:countryName               = CNstateOrProvinceName       = HBorganizationName          = LQorganizationalUnitName    = ITcommonName                = stw2.example.comemailAddress              = root@example.comX509v3 extensions:X509v3 Basic Constraints: CA:FALSENetscape Comment: OpenSSL Generated CertificateX509v3 Subject Key Identifier: 5B:8A:BD:D6:43:41:51:D0:6A:60:4D:4E:BD:8B:58:7C:F6:94:BD:A7X509v3 Authority Key Identifier: keyid:63:9E:05:A1:DA:A1:DA:74:9D:75:8D:B4:DF:D1:21:14:65:F9:DB:C6Certificate is to be certified until Aug 12 10:19:54 2026 GMT (365 days)
Sign the certificate? [y/n]:y1 out of 1 certificate requests certified, commit? [y/n]y
Write out database with 1 new entries
Data Base Updated
[root@stw CA]# ls
cacert.pem  crl        httpd.csr  index.txt.attr  newcerts  serial
certs       httpd.crt  index.txt  index.txt.old   private   serial.old
再把已经完成认证的证书发送回到Web服务器:
要先确认DNS中有stw2.example.com(Web服务器)的条目(这里已经存在此条目)
并且把DNS指向DNS服务器(这里的DNS服务器是自己)
[root@stw CA]# cd /etc/sysconfig/network-scripts/
[root@stw network-scripts]# vim ifcfg-ens33
[root@stw network-scripts]# systemctl restart network
[root@stw ~]# cd /etc/pki/CA
[root@stw CA]# scp httpd.crt root@stw2.example.com:/etc/httpd/ssl/
The authenticity of host 'stw2.example.com (192.168.100.20)' can't be established.
ECDSA key fingerprint is SHA256:R7/1dpul7cu8SnefsN2wQw5hKDL+xekk0ffasLS6OGI.
ECDSA key fingerprint is MD5:81:88:a1:16:52:83:c0:d5:59:ad:2b:3a:d5:52:02:bc.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'stw2.example.com,192.168.100.20' (ECDSA) to the list of known hosts.
root@stw2.example.com's password: 
httpd.crt                                                                               100% 4557     1.1MB/s   00:00    
[root@stw CA]# 
Web服务器查看:
[root@stw2 ssl]# ls
httpd.crt  httpd.csr  httpd.key
安装apche http扩展模块mod_ssl
[root@stw2 ~]# yum -y install mod_ssl
修改主配置文件
[root@stw2 ~]# vim /etc/httpd/conf.d/ssl.conf

在这里插入图片描述

部署网页(虚拟主机中部署)
[root@stw2 conf.d]# vim httpd-vhosts.conf 
[root@stw2 conf.d]# systemctl restart httpd

在这里插入图片描述

客户端:
查看是否能解析到Web服务器
[root@stw3 ~]# nslookup
> stw2.example.com
Server:		192.168.100.10
Address:	192.168.100.10#53Name:	stw2.example.com
Address: 192.168.100.20
将根证书传递到客户端
[root@stw3 ~]# scp root@192.168.100.10:/etc/pki/CA/cacert.pem .
The authenticity of host '192.168.100.10 (192.168.100.10)' can't be established.
ECDSA key fingerprint is SHA256:R7/1dpul7cu8SnefsN2wQw5hKDL+xekk0ffasLS6OGI.
ECDSA key fingerprint is MD5:81:88:a1:16:52:83:c0:d5:59:ad:2b:3a:d5:52:02:bc.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.100.10' (ECDSA) to the list of known hosts.
root@192.168.100.10's password: cacert.pem                                    100% 1375   324.9KB/s   00:00    
[root@stw3 ~]# ls
anaconda-ks.cfg  Desktop    Downloads             Music     Public     Videos
cacert.pem       Documents  initial-setup-ks.cfg  Pictures  Templates
在浏览器中上传,让浏览器知道这个站点是安全的

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

Web服务器:
在刚刚设置的网页中写入内容
[root@stw2 ~]# cd /var/www
[root@stw2 www]# ls
cgi-bin  html  luoqi  yyqx
[root@stw2 www]# mkdir test
[root@stw2 www]# ls
cgi-bin  html  luoqi  test  yyqx
[root@stw2 www]# cd test
[root@stw2 test]# echo ssstttwww > index.html
客户端访问

在这里插入图片描述

也可以命令访问
[root@stw3 ~]# curl -k https://192.168.100.20
ssstttwww

五、访问动态网页

Web服务器:
1、安装服务
[root@stw2 ~]# yum -y install mod_swgi
2、创建目录并且导入文件
[root@stw2 ~]# mkdir /var/www/wsgi
[root@stw2 ~]# cd /var/www/wsgi
[root@stw2 wsgi]# ls
cacert.pem  css  images  index.html  python.txt
DNS服务器:
1、将Web服务器的条目添加到DNS
[root@stw ~]# vim /var/named/stw.com
[root@stw ~]# systemctl restart network

在这里插入图片描述

Web服务器:
1、将导入进来的脚本更改后缀名并加上执行权限
[root@stw2 wsgi]# ls
cacert.pem  css  images  index.html  python.txt
[root@stw2 wsgi]# cat python.txt
def application(environ, start_response):status = '200 OK'output = 'Hello World!'response_headers = [('Content-type', 'text/plain'),('Content-Length', str(len(output)))]start_response(status, response_headers)return [output]
[root@stw2 wsgi]# mv python.txt test.py
[root@stw2 wsgi]# ll
total 12
-rw-r--r--. 1 root root 1375 Aug 12 19:27 cacert.pem
drwxr-xr-x. 2 root root   23 Aug 12 19:27 css
drwxr-xr-x. 2 root root   68 Aug 12 19:27 images
-rw-r--r--. 1 root root 2251 Aug 12 19:27 index.html
-rw-r--r--. 1 root root  282 Aug 12 19:27 test.py
[root@stw2 wsgi]# chmod +x test.py
[root@stw2 wsgi]# ll
total 12
-rw-r--r--. 1 root root 1375 Aug 12 19:27 cacert.pem
drwxr-xr-x. 2 root root   23 Aug 12 19:27 css
drwxr-xr-x. 2 root root   68 Aug 12 19:27 images
-rw-r--r--. 1 root root 2251 Aug 12 19:27 index.html
-rwxr-xr-x. 1 root root  282 Aug 12 19:27 test.py
2、更改配置文件
[root@stw2 wsgi]# vim /etc/httpd/conf.d/httpd-vhosts.conf 
[root@stw2 wsgi]# systemctl restart httpd

在这里插入图片描述

客户端访问hello world

在这里插入图片描述

web服务器:
更改配置文件
[root@stw2 wsgi]# vim /etc/httpd/conf.d/httpd-vhosts.conf 
[root@stw2 wsgi]# systemctl restart httpd

在这里插入图片描述

客户端测试

在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若转载,请注明出处:http://www.pswp.cn/web/92897.shtml
繁体地址,请注明出处:http://hk.pswp.cn/web/92897.shtml
英文地址,请注明出处:http://en.pswp.cn/web/92897.shtml

如若内容造成侵权/违法违规/事实不符,请联系英文站点网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【Android笔记】Android 自定义 TextView 实现垂直渐变字体颜色(支持 XML 配置)

Android 自定义 TextView 实现垂直渐变字体颜色(支持 XML 配置) 在 Android UI 设计中,字体颜色的渐变效果能让界面看起来更加精致与现代。常见的渐变有从左到右、从上到下等方向,但 Android 的 TextView 默认并不支持垂直渐变。…

CANopen Magic调试软件使用

一、软件安装与硬件连接1.1 系统要求操作系统:Windows 7/10/11 (64位)硬件接口:支持Vector/PEAK/IXXAT等主流CAN卡推荐配置:4GB内存,2GHz以上CPU1.2 安装步骤运行安装包CANopen_Magic_Setup.exe选择安装组件(默认全选&…

前端css学习笔记3:伪类选择器与伪元素选择器

本文为个人学习总结,如有谬误欢迎指正。前端知识众多,后续将继续记录其他知识点! 目录 前言 一、伪类选择器 1.概念 2.动态选择器(用户交互) 3.结构伪类 :first-child:选择所有兄弟元素的…

深入探索 PDF 数据提取:PyMuPDF 与 pdfplumber 的对比与实战

在数据处理和分析领域,PDF 文件常常包含丰富的文本、表格和图形信息。然而,从 PDF 中提取这些数据并非易事,尤其是当需要保留格式和颜色信息时。幸运的是,Python 社区提供了多个强大的库来帮助我们完成这项任务,其中最…

Springboot注册过滤器的三种方式(Order 排序)

一、使用 Component Order(简单但不够灵活) 适用于全局过滤器,无需手动注册,Spring Boot 会自动扫描并注册。 Component Order(1) // 数字越小,优先级越高 public class AuthFilter implements Filter {Autowired /…

电脑硬件详解

前几天我的风扇转的很快,而且cpu占用率很高,然后我在想怎么回事,然后就浅浅研究了一下电脑的硬件。 笔记本主板: 台式机主板: 图1: 图2: 电脑硬件详解 电脑的硬件是组成计算机系统的物理设…

力扣47:全排列Ⅱ

力扣47:全排列Ⅱ题目思路代码题目 给定一个可包含重复数字的序列 nums ,按任意顺序 返回所有不重复的全排列。 思路 又是任意顺序和所有不重复的排列,显而易见我们要使用回溯的办法。 首先是回溯的结束条件即新数组的长度等于nums的长度。这道题的难点…

学习笔记091——如何实现web登录时,密码复杂度校验?(后端)

1、创建工具类 /*** 密码复杂度校验* param password 密码*/ public static void validatePassword(String password) {// 至少8位if (password.length() < 8) {throw new IllegalArgumentException("密码长度至少为8位");}// 包含大小写字母if (!password.matche…

雪花算法snowflake分布式id生成原理详解,以及对解决时钟回拨问题几种方案讨论

一、前言在日趋复杂的分布式系统中&#xff0c;数据量越来越大&#xff0c;数据库分库分表是一贯的垂直水平做法&#xff0c;但是需要一个全局唯一ID标识一条数据或者MQ消息&#xff0c;数据库id自增就显然不能满足要求了。因为场景不同&#xff0c;分布式ID需要满足以下几个条…

【PCB设计经验】去耦电容如何布局?

0805 和 0603 以及更小 封装的电容用作于对中高频的去耦,其摆放位置是有要求的: 一、建议尽可能的靠近主控芯片的 电源管脚放置。 二、使用较宽和短的引线连接到电源和地过孔可以采用如下 图 4–1 中的图 ( 2 )、( 3)、 ( 4 )任意一种方式,避免使用长线或者较细的…

自动化运维实验

目录 一、实验拓扑 二、实验目的 三、实验步骤 实验思路&#xff1a; 代码部分&#xff1a; 四、实验结果&#xff1a; 一、实验拓扑 二、实验目的 利用python脚本&#xff0c;在本地&#xff0c;或者虚拟机里实现&#xff0c;设备CRC数量统计&#xff0c;并输出成表格 三、实验…

Wed前端第二次作业

一、作业1&#xff1a;完成自己学校的官网&#xff0c;动忘内容直接贴&#xff0c;至少三个不同的页面1、界面1&#xff08;1&#xff09;相关代码<!DOCTYPE html> <html lang"en"> <head><meta charset"UTF-8"><meta name&quo…

第5节 大模型分布式推理通信优化与硬件协同

前言 在分布式推理中,多设备(如GPU、CPU)之间的数据传输(通信)是连接计算的“桥梁”。如果通信效率低下,即使单设备计算能力再强,整体性能也会大打折扣。想象一下:如果工厂之间的物流卡车跑得比生产速度还慢,再多的工厂也无法提高整体产量。 本节将从最基础的单设备内…

XGBoost 的适用场景以及与 CNN、LSTM 的区别

XGBoost 的核心优势与适用场景XGBoost 是一种梯度提升决策树算法&#xff0c;属于集成学习方法。它在处理结构化/表格化数据方面表现极其出色&#xff0c;是 Kaggle 竞赛和工业界广泛应用的“冠军”模型。其核心优势和应用场景包括&#xff1a;1. 结构化/表格化数据数据形式&a…

快速设计简单嵌入式操作系统(3):动手实操,基于STC8编写单任务执行程序,感悟MCU指令的执行过程

引言 前面我们陆续学习了操作系统常见的基础概念&#xff0c;接着简单了解了一下8051单片机的内存结构和执行顺序切换的相关概念。接下来&#xff0c;我们就开始进行实操&#xff0c;基于8051单片机STC8来编写一个简单的操作系统&#xff0c;这里我们先实现一个单任务的执行程…

Spring AI Alibaba - 聊天机器人快速上手

本节对应 Github&#xff1a;https://github.com/JCodeNest/JCodeNest-AI-Alibaba/tree/master/spring-ai-alibaba-helloworld 本文将以阿里巴巴的通义大模型为例&#xff0c;通过 Spring AI Alibaba 组件&#xff0c;手把手带你完成从零到一的构建过程&#xff1a;首先&#…

串口通信学习

不需要校验位就选8位&#xff0c;需要校验位就选9位&#xff01;USRTUSART框图STM32的外设引脚这是USART的基本结构。数据帧&#xff0c;八位是这个公式还是很重要的&#xff01;如果在编辑器里面使用printf打印汉字的话&#xff0c;会出现乱码的话&#xff0c;前提是你的编码格…

面试经典150题[001]:合并两个有序数组(LeetCode 88)

合并两个有序数组&#xff08;LeetCode 88&#xff09; https://leetcode.cn/problems/merge-sorted-array/?envTypestudy-plan-v2&envIdtop-interview-150 1. 题目背景 你有两个已经排好序的数组&#xff1a; nums1&#xff1a;前面是有效数字&#xff0c;后面是空位&…

快速安装达梦8测试库

计划&#xff1a;数据库名实例名PORT_NUMMAL_INST_DW_PORTMAL_HOSTMAL_PORTMAL_DW_PORTDMDWDBINST_1533615101192.168.207.612510135101*****[2025-08-11 15:14:34]***** Last login: Fri Jul 25 17:36:04 2025 from 192.168.88.48 [rootdm01 ~]# ip a 1: lo: <LOOPBACK,UP,…

Hive中优化问题

一、小文件合并优化Hive中的小文件分为Map端的小文件和Reduce端的小文件。(1)、Map端的小文件优化是通过CombineHiveInputFormat操作。相关的参数是&#xff1a;set hive.input.formatorg.apache.hadoop.hive.ql.io.CombineHiveInputFormat;(2)、Reduce端的小文件合并Map端的小…