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

相关文章

Python并行处理实战之如何使用ProcessPoolExecutor加速计算

《Python并行处理实战之如何使用ProcessPoolExecutor加速计算》Python提供了多种并行处理的方式,其中concurrent.futures模块的ProcessPoolExecu... 目录简介完整代码示例代码解释1. 导入必要的模块2. 定义处理函数3. 主函数4. 生成数字列表5.

Java Spring 中的监听器Listener详解与实战教程

《JavaSpring中的监听器Listener详解与实战教程》Spring提供了多种监听器机制,可以用于监听应用生命周期、会话生命周期和请求处理过程中的事件,:本文主要介绍JavaSprin... 目录一、监听器的作用1.1 应用生命周期管理1.2 会话管理1.3 请求处理监控二、创建监听器2.1 Ser

Apache 高级配置实战之从连接保持到日志分析的完整指南

《Apache高级配置实战之从连接保持到日志分析的完整指南》本文带你从连接保持优化开始,一路走到访问控制和日志管理,最后用AWStats来分析网站数据,对Apache配置日志分析相关知识感兴趣的朋友... 目录Apache 高级配置实战:从连接保持到日志分析的完整指南前言 一、Apache 连接保持 - 性

在Spring Boot中实现HTTPS加密通信及常见问题排查

《在SpringBoot中实现HTTPS加密通信及常见问题排查》HTTPS是HTTP的安全版本,通过SSL/TLS协议为通讯提供加密、身份验证和数据完整性保护,下面通过本文给大家介绍在SpringB... 目录一、HTTPS核心原理1.加密流程概述2.加密技术组合二、证书体系详解1、证书类型对比2. 证书获

MQTT SpringBoot整合实战教程

《MQTTSpringBoot整合实战教程》:本文主要介绍MQTTSpringBoot整合实战教程,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考... 目录MQTT-SpringBoot创建简单 SpringBoot 项目导入必须依赖增加MQTT相关配置编写

JavaScript实战:智能密码生成器开发指南

本文通过JavaScript实战开发智能密码生成器,详解如何运用crypto.getRandomValues实现加密级随机密码生成,包含多字符组合、安全强度可视化、易混淆字符排除等企业级功能。学习密码强度检测算法与信息熵计算原理,获取可直接嵌入项目的完整代码,提升Web应用的安全开发能力 目录

Redis迷你版微信抢红包实战

《Redis迷你版微信抢红包实战》本文主要介绍了Redis迷你版微信抢红包实战... 目录1 思路分析1.1hCckRX 流程1.2 注意点①拆红包:二倍均值算法②发红包:list③抢红包&记录:hset2 代码实现2.1 拆红包splitRedPacket2.2 发红包sendRedPacket2.3 抢

springboot项目redis缓存异常实战案例详解(提供解决方案)

《springboot项目redis缓存异常实战案例详解(提供解决方案)》redis基本上是高并发场景上会用到的一个高性能的key-value数据库,属于nosql类型,一般用作于缓存,一般是结合数据... 目录缓存异常实践案例缓存穿透问题缓存击穿问题(其中也解决了穿透问题)完整代码缓存异常实践案例Red

Spring Boot拦截器Interceptor与过滤器Filter深度解析(区别、实现与实战指南)

《SpringBoot拦截器Interceptor与过滤器Filter深度解析(区别、实现与实战指南)》:本文主要介绍SpringBoot拦截器Interceptor与过滤器Filter深度解析... 目录Spring Boot拦截器(Interceptor)与过滤器(Filter)深度解析:区别、实现与实

基于C#实现MQTT通信实战

《基于C#实现MQTT通信实战》MQTT消息队列遥测传输,在物联网领域应用的很广泛,它是基于Publish/Subscribe模式,具有简单易用,支持QoS,传输效率高的特点,下面我们就来看看C#实现... 目录1、连接主机2、订阅消息3、发布消息MQTT(Message Queueing Telemetr