45笔记

作者: 口口帅日日 | 来源:发表于2019-09-26 08:27 被阅读0次

今日内容

   nginxRewrite-redirect-permanent
   nginxRewrite-break-last
   nginxHttps-介绍
   nginxHttps-证书申请与颁发
   nginxHttps-类型与注意事项
   nginxHttps-单台环境配置Https
   nginxHttps-集群环境配置Https
   nginxHttps-集群架构接入Https
   nginxHttps-阿里云申请Https
   nginxHttps-阿里云SLB+ECS实现Https
   nginxHttps-场景-部分URL不走Https
   nginxHttps-相关优化参数

rewrite中的flag

跳转
    redirect  302 临时跳转    旧网站无影响,新网站无排名
    permanent 301 永久跳转    新网站有排名,旧网站清空

  http -->https 302 浏览器不会记住新域名
  http -->https 301 会记住新域名(即使nginx停掉,也会跳转)

last #本条规则匹配完成后,继续向下匹配新的location URL规则
break #本条规则匹配完成即终止,不在匹配后面的任何规则
当rewrite规则遇到break,本location{} 与其他location{} 所有rewrite/return规则都不在执行
当rewrite规则遇到last后,本location{}里后续rewrite/return规则不执行,但重写后的url再次从头开始执行所有规则,哪个匹配执行哪个

###HTTPS
1.什么是Https
2.为什么要使用Https
3.模拟不使用Https的劫持和篡改?
4.Https通讯是如何确定双方的身份?
5.Https证书类型、购买指南、注意事项?
6.如何实现单台Https、又如何实现集群Https?
7.如何将Https集成集群架构实现全站Https?
8.有一个url地址不希望走https,其他正常走https?

1.什么是Https
  TTPS(全称:Hyper Text Transfer Protocol over Secure Socket Layer 或 Hypertext Transfer Protocol Secure,超文本传输安全协议),
  是以安全为目标的HTTP通道,简单讲是HTTP的安全版
2.为什么要使用Https
  因为http不安全,会遭到劫持或者篡改。使用https过程中传输数据是加密的。他人无法窃取或者篡改。   
image.png

 location / {
        root   /opt/app/code/;
    random_index on;
    index  index.html index.htm;
    sub_filter '<h1>Admin' '<h1>ggggg';  //第一个参数是要被替换的,第二个参数是替换后的
    sub_filter_once off;   //替换所有的,默认是on,替换第一个
 }
image.png
image.png
.HTTPS证书购买指南 123.com
保护1个域名 www                              www.123.com
保护5个域名 www images cdn test m            docs.123.com  www.123.com iamges.123.com
通配符域名 *.123.com
   
HTTPS注意事项
Https不支持续费,证书到期需重新申请新并进行替换。
Https不支持三级域名解析,如 test.m.testboy.com。 
Https显示绿色,说明整个网站的url都是https的,并且都是安全的
Https显示黄色,说明网站代码中有部分URL地址是http不安全协议的。  
Https显示红色,要么证书是假的,要么证书已经过期。

#前提:必须有--with-http_ssl_module模块
#创建存放ssl证书的路径
[root@Nginx ~]# mkdir -p /etc/nginx/ssl_key
[root@Nginx ~]# cd /etc/nginx/ssl_key

单台实现https功能

1.生成证书 (密码1234)
[root@Nginx ~]# openssl genrsa -idea -out server.key 2048

2.生成自签证书,同时去掉私钥的密码
openssl req -days 36500 -x509 \
-sha256 -nodes -newkey rsa:2048 -keyout server.key -out server.crt


3.配置nginx
[root@web01 conf.d]# cat s.testux.com.conf 
server {
listen 443 ssl;      #启用ssl功能
server_name s.testxu.com;
root /code;
ssl_certificate ssl_key/server.crt;      #证书请求文件
ssl_certificate_key ssl_key/server.key;    #私钥文件

location / {
    index index.html;
}
}
server {
listen 80;
server_name s.testxu.com;
return 302 https://$http_host$request_uri;  
}

集群实现https

image.png
user与lsb之间公网通讯使用https,lsb与web集群内网中
不会有公网干扰,使用http效率比较高


1.先配置好后端的web节点
2.在负载均衡上申请证书(如果之前已经申请,可以执行推送)
3.配置nginx负载均衡-->http协议
4.配置nginx负载均衡--->转为https协议

[root@lb01 conf.d]# cat proxy_s.testxu.com.conf 
upstream webs {
server 172.16.1.7:80;
server 172.16.1.8:80;
}

server {
listen 443 ssl;
ssl_certificate ssl_key/server.crt;
ssl_certificate_key ssl_key/server.key;

server_name s.testxu.com;
location / {
    proxy_pass http://webs;
    include proxy_params;
}
}
server {
listen 80;
server_name s.testxu.com;

if ($request_uri !~* "^/abc") {
    return 302 https://$http_host$request_uri;   #跳转到s.testxu.com
}

location / {
    proxy_pass http://webs;
    include proxy_params;
}
    }

 #同时在172.16.1.7与172.16.1.8下准备相同的目录与配置文件
[root@web01 conf.d]echo 'web01' >/code/index.html
[root@web02 conf.d]echo 'web02' >/code/index.html
[root@web01 conf.d]# cat s.testxu.com.conf    
server {

listen 80;
server_name s.testxu.com;
root /code;

location / {
index index.html;
}

}

相关文章

网友评论

      本文标题:45笔记

      本文链接:https://www.haomeiwen.com/subject/ppewuctx.html