day36-rewrite实战

01.Rewirte 跳转
配置nginx
[root@web01:conf.d]#cat test.conf
server {
        listen 80;
        server_name test.oldboy.com;
        root /code/test/;

        location / {
        rewrite /1.html /2.html;
        rewrite /2.html /3.html;
        }

        location /2.html {
        rewrite /2.html /a.html;
        }

        location /3.html {
        rewrite /3.html /b.html;
        }
}
[root@web01:conf.d]#mkdir /code/test
[root@web01:conf.d]#echo 22222 > /code/test/2.html
[root@web01:conf.d]#echo 33333 > /code/test/3.html
[root@web01:conf.d]#echo aaaaa > /code/test/a.html
[root@web01:conf.d]#echo bbbbb > /code/test/b.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


测试break标签: 停止向后匹配直接返回2.html中的内容
[root@web01:conf.d]#cat test.conf
server {
        listen 80;
        server_name test.oldboy.com;
        root /code/test/;

        location / {
        rewrite /1.html /2.html break;
        rewrite /2.html /3.html;
        }

        location /2.html {
        rewrite /2.html /a.html;
        }

        location /3.html {
        rewrite /3.html /b.html;
        }
}

测试last标签: 停止向后匹配,浏览器重新对2.hmtl向服务端发起请求

[root@web01:conf.d]#cat test.conf
server {
        listen 80;
        server_name test.oldboy.com;
        root /code/test/;

        location / {
        rewrite /1.html /2.html last;
        rewrite /2.html /3.html;
        }

        location /2.html {
        rewrite /2.html /a.html;
        }

        location /3.html {
        rewrite /3.html /b.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


break: 停止向下匹配直接返回结果
last: 停止向下匹配,重新发起请求到服务器
2.0rewrite301 和 302 跳转
redirect	返回302临时重定向,地址栏会显示跳转后的地址  每次请求源站
permanent	返回301永久重定向,地址栏会显示跳转后的地址  只请求1次源站
[root@web01:conf.d]#cat test.conf
server {
        listen 80;
        server_name   test.oldboy.com;
        root /code;

        location /test {
                rewrite ^(.*)$  http://www.baidu.com redirect;		# 临时跳转
                #return 302 http://www.oldboy.com;					# 临时跳转

                #return 301 http://www.oldboy.com;					# 永久跳转
                #rewrite ^(.*)$  http://www.oldboy.com permanent;   # 永久跳转

        }
}
[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

http 状态:

200   OK   200-300之间都是正常访问
301        永久跳转
302		   临时跳转
304		   缓存
307		   内部跳转
401        验证没有通过
403		   有目录没资源
404        没有代码目录
502        坏的网关,数据库无响应
503        负载过高
504		   数据库超时,无法连接
3.rewirte 跳转案例
案例1.用户访问/abc/1.html实际上真实访问的是/ccc/bbb/2.html
[root@web01:conf.d]#cat test.conf
server {
        listen 80;
        server_name   test.oldboy.com;
        root /code;

        location /abc {
           rewrite ^(.*)$  /ccc/bbb/2.html;
        }
}
[root@web01:conf.d]#mkdir /code/ccc/bbb -p
[root@web01:conf.d]#echo rewrite......... > /code/ccc/bbb/2.html
[root@web01:conf.d]#cat /code/ccc/bbb/2.html
rewrite.........

[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


案例2.用户访问/2018/ccc/2.html实际上真实访问的是/2014/ccc/bbb/2.html
[root@web01:conf.d]#cat test.conf
server {
        listen 80;
	      server_name test.oldboy.com;
        location / {
            root /code;
            index index.html;
        }
        location /2018 {
          rewrite ^/2018/(.*)$ /2014/$1 redirect;
        }
}
[root@web01:conf.d]#mkdir /code/2014/test/ -p
[root@web01:conf.d]#echo 2014.... > /code/2014/test/1.html
[root@web01:conf.d]#echo 2.... > /code/2014/test/2.html
[root@web01:conf.d]#echo 3.... > /code/2014/test/3.html

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

域名跳转:
[root@web01:conf.d]#cat test.conf
server {
        listen 80;
	server_name test.oldboy.com;
        location / {
                root /code;
                index index.html;
        }
        location /abc {
                rewrite (.*) www.baidu.com redirect;	# 临时跳转
        }
}


案例4.访问course-11-22-33.html实际上真实访问的是/course/11/22/33/course_33.html
[root@web01:conf.d]#cat test.conf
server {
        listen 80;
	server_name test.oldboy.com;
        root /code;
        index index.html;
        location / {
          #灵活配法
          rewrite ^/course-(.*)-(.*)-(.*).html$ /course/$1/$2/$3/course_$3.html redirect;
          #固定配法
          #rewrite ^/course-(.*) /course/11/22/33/course_33.html redirect;
        }
}
[root@web01:conf.d]#nginx -t
[root@web01:conf.d]#systemctl restart nginx
[root@web01:conf.d]#mkdir /code/course/11/22/33 -p
#echo 3333333333333 > /code/course/11/22/33/course_33.html
##浏览器访问test.oldboy.com/course-11-22-33.html



案例5.维护页面配置
[root@web01:conf.d]#cat test.conf
server {
    listen 80;
    server_name test.oldboy.com;
    root /code;
    charset utf-8,gbk;

    location / {
        index index.html;
        set $ip 0;       # 设置变量为0
        if ($remote_addr = "10.0.0.1"){
            set $ip 1;   # 如果来源IP为0.1则设置为1
        }
        if ($ip = 0){    # 判断如果变量为0 则跳转维护页面
            rewrite ^(.*)$ /wh.html break;
        }
    }

}

[root@web01:conf.d]#nginx -t
[root@web01:conf.d]#systemctl restart nginx

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

PV: 点击的数量,打开网站算一个PV,刷新1次算1个PV。点击里面任意文章累加1个PV
每个用户访问京东大概得PV是多少?  20个PV
每个用户小说访问大概得PV是多少? 一章(一页)就是一个PV

UV: 一台硬件设备为一个UV,一个UV一个用户。

独立IP: 出口IP,公网IP地址
可以独立算出一个网站的大概得PV UV和独立IP地址。
学校---->独立公网IP出去上网
比例公司100个人--->独立IP1个
100个人有几个人访问京东--->就算几个硬件设备--->UV的数量

30万PV
UV? 计算每个硬件设备点击的数量*UV=30万PV
京东: 300000/100=3000UV
独立的IP: 3000/5-10比例 = 300 -1000之间独立公网IP地址。

100万PV?


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
git-rewrite-author是一个Git命令,用于修改提交历史中的作者信息。 在使用Git进行项目开发时,每次进行提交操作都会记录下提交者的作者信息,包括姓名和邮箱。有时候我们可能因为一些原因需要修改这些作者信息,比如提交者输入了错误的名字或邮箱地址,或者是因为合并了其他仓库的代码,希望统一提交者的作者信息。 使用git-rewrite-author命令可以轻松地修改提交历史中的作者信息。它提供了一种简单的方式来重写Git仓库的提交者作者信息。使用该命令需要提供被修改的提交范围或者特定提交的哈希值,以及修改后的作者信息。 具体使用git-rewrite-author命令的步骤如下: 1. 打开命令行终端,进入到项目的Git仓库目录中。 2. 运行git-rewrite-author命令,并提供需要修改的提交范围或者特定提交的哈希值,以及修改后的作者信息。 3. Git会通过找到需要修改的提交对象,并将其中的作者信息进行修改。修改后的提交对象会被重新写入Git仓库中。 需要注意的是,使用git-rewrite-author命令会修改提交历史,因此需要小心操作。如果在多人协作的项目中使用该命令,需要确保与其他开发者达成一致,并尽量避免在共享的分支上进行修改。 总之,git-rewrite-author是一个方便修改提交历史作者信息的Git命令,可以帮助我们修正错误的作者信息或者统一项目中的作者信息。但在使用时需要谨慎操作,避免对其他开发者造成不必要的困扰。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值