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.com

10.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.com

MariaDB [(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 nginx

hosts修改
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.zip

unzip 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 nginx




2.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;			# 增加的内容
        }
}

注意:

网站静态资源需要优化 比如大的图片压缩成小的
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值