HTTPS服務

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端的小…