美文网首页
新架构第5天

新架构第5天

作者: Liang_JC | 来源:发表于2020-08-08 12:42 被阅读0次

Q1、rewrite几种规则案例演示区别

[root@Centos7 conf.d]# vim web.conf
server_tokens off;

server {
        listen 192.168.37.87:80;
        listen 192.168.37.87:443 ssl;
        server_name test.magedu.net;
        access_log logs/test.magedu.net.access.log json;
        ssl_certificate /apps/nginx/ssl/magedu.net.crt;
        ssl_certificate_key /apps/nginx/ssl/magedu.net.key;
        ssl_session_cache shared:sslcache:20m;
        ssl_session_timeout 10m;
        location / {
                root /data/site1;
                index index.html;
                if ( $scheme = http ) { 
                        rewrite ^/(.*)$ https://test.magedu.net/$1 permanent;   #http跳转到https
                }
                if ( !-f $request_filename ) {
                        rewrite .* http://test.magedu.net/index.html;       #输入错误地址跳转到主页
                }
        }
        location /last {
                rewrite ^/last/(.*)$ /info/$1 last;     #访问last目录会跳转到info目录
                return 888 "last";
        }
}
[root@Centos7 conf.d]# nginx -s reload
[root@Centos7 conf.d]# mkdir /data/site1/{last,info}
[root@Centos7 conf.d]# echo infomation > /data/site1/info/index.html
[root@Centos7 conf.d]# chown nginx.nginx -R /data/site1/

#客户端测试
[root@centos6 ~]$ curl test.magedu.net      #跳转到https
<html>
<head><title>301 Moved Permanently</title></head>
<body>
<center><h1>301 Moved Permanently</h1></center>
<hr><center>nginx</center>
</body>
</html>
[root@centos6 ~]$ curl -kL test.magedu.net
test

[root@centos6 ~]$ curl -kL test.magedu.net/1234412      #错误页面跳转到主页
test
[root@centos6 ~]$ curl -kL test.magedu.net/last/index.html  #访问last跳转到info
infomation

Q2、使用proxy反向代理后端多台web服务器

[root@Centos7 conf.d]# vim web.conf
server_tokens off;

upstream local {
        server 192.168.37.67;
        server 192.168.37.77;
        server 127.0.0.1:9001 backup;
}

server {
        listen 80;
        server_name test.magedu.net;
        location / {
                proxy_pass http://local;
        }
}

server {
        listen 127.0.0.1:9001;
        root /data/site2;
        index index.html;
        access_log logs/test.magedeu.net.sorry.log;
}
[root@Centos7 conf.d]# echo sorry > /data/site2/index.html

#客户端测试
[root@centos6 ~]$ while :;do curl test.magedu.net;sleep 0.5;done
RS2
RS1
RS2
RS1
RS2
RS1
RS2
RS1
RS2
RS1
RS2
RS1
RS2
RS1
RS2
RS1
RS2

相关文章

  • 海量运维、运营规划之道

    第1部分质量 第1章规划/2 1.1架构规划/2 1.1.1新趋势、新机遇、新挑战/2 1.1.2产品、架构、成本...

  • 新架构第1天

    Q1、Ubuntu server18.04的安装,优化系统 选择安装语言image.png 选择第一项安装serv...

  • 新架构第2天

    Q1、几种IO模型的原理 阻塞IO模型应用程序接收到用户一个请求,应用程序发起系统调用内核完成工作,内核从网络或者...

  • 新架构第3天

    Q1、基于location实现基于域名虚拟主机 测试结果: Q2、nginx自定义日志路径,配置访问日志为json...

  • 新架构第5天

    Q1、rewrite几种规则案例演示区别 Q2、使用proxy反向代理后端多台web服务器

  • 新架构第6天

    Q1、编译安装tengine,openresty Q2、搭建基于LNMP的WordPress站点 Q3、详解hap...

  • MVC和MVP

    Android mvp 架构的自述 如何更高效的使用MVP以及官方MVP架构解析 老的MVC架构 新的MVP架构 ...

  • 2019-08-26

    架构设计 新的一周,新的迭代~新的迭代要做消息中心,今天下午一直在写架构设计文档。这次架构设计文档,我以专栏 - ...

  • 新一代银行 IT 架构

    第 1 章 引言 第 2 章 分布式架构理论及典型实践 第 3 章 当前主流的 IT 架构分析 第 4 章 新一代...

  • 数据库ROOM-Google新推

    前言 今年,谷歌新推了不少东西,在看其新架构Architecture Components(AC架构是一个类似M...

网友评论

      本文标题:新架构第5天

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