day37-https实战

2024-08-22 12:20
文章标签 实战 https day37

本文主要是介绍day37-https实战,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

1.知识点补充:

四层代理转发数据库
目的: 通过10.0.0.4 使用ssh远程连接到web01
ssh--->10.0.0.4:2222 ---------->172.16.1.7:22
xshell-->创建会话-->10.0.0.4 端口 2222
Linux系统  ssh 10.0.0.4 -p2222作业:
目的: 实现连接10.0.0.4的5555端口转发到后端数据库的172.16.1.51 3306端口
web01测试远程连接数据库方式:
1.安装mysql命令
2.mysql -h 172.16.1.51 -ulzy -plzy123.com10.0.0.4  5555 ---------> 172.16.1.51:3306
测试通过四层连接数据库:
mysql -h 10.0.0.4 -P5555 -ulzy -plzy123.com[root@web01:~]#mysql -h 10.0.0.4 -P5555 -ulzy -plzy123.comMariaDB [(none)]> quit
Bye远程连接数据库工具测试:

2.https

面试题:
https在那一层进行数据加密
表示层
https的加密流程
1.浏览器访问服务端
2.服务端返回证书包含公钥给浏览器
3.浏览器向CA机构验证证书的合法性
4.如果不合法则提示警告信息
5.如果合法浏览器生成一个随机数 使用R表示
6.使用证书的公钥将R随机数进行加密传输给服务器
7.服务器使用私钥对公钥进行解密拿到客户端的R随机数
8.服务端使用R随机数对数据进行加密传输给浏览器
9.至此双方使用对称式加密方式进行数据传输

3.http 劫持

1.web01作为正常的网站服务
[root@web01:~]#cd /etc/nginx/conf.d/
[root@web01:conf.d]#
[root@web01:conf.d]#cat test.conf
server {listen 80;server_name www.lzy.com;root /data/code;index index.html;charset utf-8;
}
[root@web01:conf.d]#mkdir /data/code -p
[root@web01:conf.d]#vim /data/code/index.html
[root@web01:conf.d]#nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@web01:conf.d]#systemctl restart nginx
[root@web01:conf.d]#cat /data/code/index.html
<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>我是title</title>
</head>
<body>
<article><header><h1>我是妹妹</h1><p>创建时间:<time pubdate="pubdate">2020/5/20</time></p></header><p><b>Aticle</b>第一次用h5写文章,好他*的紧张...</p><footer><p><small>版权所有!</small></p></footer>
</article>
</body>
</html>2.WEB02作为劫持的网站
[root@web02:~]#cd /etc/nginx/conf.d/
[root@web02:conf.d]#
[root@web02:conf.d]#cat jc.conf
upstream jiechi {server 10.0.0.7:80;
}server {listen 80;server_name www.lzy.com;location / {proxy_pass http://jiechi;proxy_set_header Host $http_host;sub_filter '<h1>我是妹妹' '<h1>澳门赌场 德州扑克 牛牛 老虎机随时提现 ';sub_filter '<b>Aticle</b>第一次用h5写文章,好他*的紧张...' '<img src="https://x0.ifengimg.com/ucms/2021_43/1237F0C7C41433B5C3EB0762D070D35739927C0B_size388_w1920_h1080.jpg">';sub_filter '<small>版权所有' ' <small>开源';}
}[root@web02:conf.d]#nginx -t
[root@web02:conf.d]#systemctl restart nginxhosts修改
10.0.0.8  www.lzy.com

浏览器访问测试:

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

4.证书类型

域名型 DV	 个人站点 博客 论坛
企业型 OV	 传统企业网站 中小型互联网公司
增强型 EV   金融 政府机构访问网站证书的颜色
绿色    # 表示所有的资源都为https
红色    # 表示假的证书或者证书已过期
黄色    # 表示部分资源为http的外链保护域名:
保护一个域名 www                     # 1个证书对应一个域名
保护五个域名 www images cdn test m   # 1个证书可以保护多个域名
通配符域名 *.oldboy.com				# 1个证书可以保护所有的域名

5.证书部署

只配置的是https服务 端口443
[root@web01:conf.d]#cat s.conf
server {listen 443 ssl;server_name download.linuxnc.com;ssl_certificate   conf.d/server.crt;ssl_certificate_key  conf.d/server.key;location / {root /code;index index.html;}
}上传证书到/etc/nginx/conf.d目录下
[root@web01:~]#cd /etc/nginx/conf.d/
[root@web01:conf.d]#
[root@web01:conf.d]#ll
total 52
-rw-r--r-- 1 root root _download.linuxnc.com_nginx.zipunzip 14499054_download.linuxnc.com_nginx.zip修改证书的名称和配置文件一致
[root@web01:conf.d]#mv download.linuxnc.com.pem server.crt
[root@web01:conf.d]#mv download.linuxnc.com.key server.key[root@web01:conf.d]#nginx -t
[root@web01:conf.d]#systemctl restart nginx

访问测试:

download.linuxnc.com:443

配置监听80端口跳转443
[root@web01:conf.d]#cat s.conf
server {listen 443 ssl;server_name download.linuxnc.com;ssl_certificate   conf.d/server.crt;ssl_certificate_key  conf.d/server.key;location / {root /code;index index.html;}
}#配置将用户访问http请求强制跳转https
server {listen 80;server_name download.linuxnc.com;return 302 https://$server_name$request_uri;
}

6.wordpress 单台实现 https

WEB01实现HTTPS
[root@web01:conf.d]#cat wordpress.conf
server {listen 443 ssl;server_name www.wp.com;root /code/wp;ssl_certificate   conf.d/server.crt;ssl_certificate_key  conf.d/server.key;location / {index index.php index.html;}location ~ \.php$ {fastcgi_pass 127.0.0.1:9000;fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;include fastcgi_params;}
}#配置将用户访问http请求强制跳转https
server {listen 80;server_name www.wp.com;return 302 https://$server_name$request_uri;
}

7.集群实现 https

1.web01的wordpress配置取消https设置 还原成80
[root@web01:conf.d]#cat wordpress.conf
server {listen 80;server_name www.wp.com;root /code/wp;location / {index index.php index.html;}location ~ \.php$ {fastcgi_pass 127.0.0.1:9000;fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;include fastcgi_params;}
}
[root@web01:conf.d]#nginx -t
[root@web01:conf.d]#systemctl restart nginx2.10.0.0.5配置证书
[root@lb01:~]#cd /etc/nginx/conf.d/
[root@lb01:conf.d]#cat proxy.conf
upstream webs {server 10.0.0.7;server 10.0.0.8;
}
server {listen 443 ssl;server_name www.wp.com;ssl_certificate   /etc/nginx/ssl/server.crt;ssl_certificate_key  /etc/nginx/ssl/server.key;location / {proxy_pass http://webs;include proxy_params;}}#配置将用户访问http请求强制跳转https
server {listen 80;server_name www.wp.com;return 302 https://$server_name$request_uri;
}# 创建证书的目录
[root@lb01:nginx]#mkdir /etc/nginx/ssl
# 拷贝证书到负载均衡
[root@lb01:nginx]#cd ssl/
[root@lb01:ssl]#scp 10.0.0.7:/etc/nginx/conf.d/server.* .#语法测试重启服务
[root@lb01:ssl]#nginx -t
[root@lb01:ssl]#systemctl restart nginx测试:
修改hosts
10.0.0.5  www.wp.com

访问测试页面乱码 需要修改 PHP 支持解析 HTTPS 协议。

web01和web02需要添加一条配置:
[root@web01:conf.d]#cat wordpress.conf
server {listen 80;server_name www.wp.com;root /code/wp;location / {index index.php index.html;}location ~ \.php$ {fastcgi_pass 127.0.0.1:9000;fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;include fastcgi_params;fastcgi_param HTTPS on;			# 增加的内容}
}

注意:

网站静态资源需要优化 比如大的图片压缩成小的

这篇关于day37-https实战的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1096257

相关文章

SQL Server跟踪自动统计信息更新实战指南

《SQLServer跟踪自动统计信息更新实战指南》本文详解SQLServer自动统计信息更新的跟踪方法,推荐使用扩展事件实时捕获更新操作及详细信息,同时结合系统视图快速检查统计信息状态,重点强调修... 目录SQL Server 如何跟踪自动统计信息更新:深入解析与实战指南 核心跟踪方法1️⃣ 利用系统目录

java中pdf模版填充表单踩坑实战记录(itextPdf、openPdf、pdfbox)

《java中pdf模版填充表单踩坑实战记录(itextPdf、openPdf、pdfbox)》:本文主要介绍java中pdf模版填充表单踩坑的相关资料,OpenPDF、iText、PDFBox是三... 目录准备Pdf模版方法1:itextpdf7填充表单(1)加入依赖(2)代码(3)遇到的问题方法2:pd

PyTorch中的词嵌入层(nn.Embedding)详解与实战应用示例

《PyTorch中的词嵌入层(nn.Embedding)详解与实战应用示例》词嵌入解决NLP维度灾难,捕捉语义关系,PyTorch的nn.Embedding模块提供灵活实现,支持参数配置、预训练及变长... 目录一、词嵌入(Word Embedding)简介为什么需要词嵌入?二、PyTorch中的nn.Em

在IntelliJ IDEA中高效运行与调试Spring Boot项目的实战步骤

《在IntelliJIDEA中高效运行与调试SpringBoot项目的实战步骤》本章详解SpringBoot项目导入IntelliJIDEA的流程,教授运行与调试技巧,包括断点设置与变量查看,奠定... 目录引言:为良驹配上好鞍一、为何选择IntelliJ IDEA?二、实战:导入并运行你的第一个项目步骤1

Spring Boot3.0新特性全面解析与应用实战

《SpringBoot3.0新特性全面解析与应用实战》SpringBoot3.0作为Spring生态系统的一个重要里程碑,带来了众多令人兴奋的新特性和改进,本文将深入解析SpringBoot3.0的... 目录核心变化概览Java版本要求提升迁移至Jakarta EE重要新特性详解1. Native Ima

Spring Boot 与微服务入门实战详细总结

《SpringBoot与微服务入门实战详细总结》本文讲解SpringBoot框架的核心特性如快速构建、自动配置、零XML与微服务架构的定义、演进及优缺点,涵盖开发环境准备和HelloWorld实战... 目录一、Spring Boot 核心概述二、微服务架构详解1. 微服务的定义与演进2. 微服务的优缺点三

SpringBoot集成MyBatis实现SQL拦截器的实战指南

《SpringBoot集成MyBatis实现SQL拦截器的实战指南》这篇文章主要为大家详细介绍了SpringBoot集成MyBatis实现SQL拦截器的相关知识,文中的示例代码讲解详细,有需要的小伙伴... 目录一、为什么需要SQL拦截器?二、MyBATis拦截器基础2.1 核心接口:Interceptor

从入门到进阶讲解Python自动化Playwright实战指南

《从入门到进阶讲解Python自动化Playwright实战指南》Playwright是针对Python语言的纯自动化工具,它可以通过单个API自动执行Chromium,Firefox和WebKit... 目录Playwright 简介核心优势安装步骤观点与案例结合Playwright 核心功能从零开始学习

Java docx4j高效处理Word文档的实战指南

《Javadocx4j高效处理Word文档的实战指南》对于需要在Java应用程序中生成、修改或处理Word文档的开发者来说,docx4j是一个强大而专业的选择,下面我们就来看看docx4j的具体使用... 目录引言一、环境准备与基础配置1.1 Maven依赖配置1.2 初始化测试类二、增强版文档操作示例2.

MySQL 多列 IN 查询之语法、性能与实战技巧(最新整理)

《MySQL多列IN查询之语法、性能与实战技巧(最新整理)》本文详解MySQL多列IN查询,对比传统OR写法,强调其简洁高效,适合批量匹配复合键,通过联合索引、分批次优化提升性能,兼容多种数据库... 目录一、基础语法:多列 IN 的两种写法1. 直接值列表2. 子查询二、对比传统 OR 的写法三、性能分析