nginx流量拷贝功能介绍


当前第2页 返回上一页

1

2

3

4

5

6

7

8

9

10

11

12

location / {

    mirror /mirror;

    mirror_request_body off;

    proxy_pass http://backend;

}

location = /mirror {

    internal;

    proxy_pass http://log_backend;

    proxy_pass_request_body off;

    proxy_set_header Content-Length "";

    proxy_set_header X-Original-URI $request_uri;

}

前面我们安装了Nginx,但是里面没有包含我们所需的ngx_http_mirror_module模块,因此,真正要使用的时候最好还是采用自定义安装,即从源码构建

首先,下载源码 http://nginx.org/en/download.html

接下来,编译安装,例如:

1

2

3

4

5

6

7

8

9

10

11

./configure

    --sbin-path=/usr/local/nginx/nginx

    --conf-path=/usr/local/nginx/nginx.conf

    --pid-path=/usr/local/nginx/nginx.pid

    --with-http_ssl_module

    --without-http_limit_req_module

    --without-http_mirror_module

    --with-pcre=../pcre-8.43

    --with-zlib=../zlib-1.2.11

    --add-module=/path/to/ngx_devel_kit

    --add-module=/path/to/lua-nginx-module

1

make & make install

配置

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

upstream api.abc.com {

server 127.0.0.1:8080;

}

upstream tapi.abc.com {

    server 127.0.0.1:8081;

}

server {

    listen 80;

   # 源站点

    location /api {

        proxy_pass http://api.cjs.com;

        proxy_set_header Host $host;

        proxy_set_header X-Real-IP $remote_addr;

        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

        # 流量复制

mirror /newapi;

mirror /mirror2;

mirror /mirror3;

# 复制请求体

mirror_request_body on;

    }

    # 镜像站点

    location /tapi {

        proxy_pass http://tapi.cjs.com$request_uri;

        proxy_pass_request_body on;

        proxy_set_header Host $host;

        proxy_set_header X-Real-IP $remote_addr;

        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

    }

}

相关推荐:nginx教程

以上就是nginx流量拷贝功能介绍的详细内容,更多文章请关注木庄网络博客

返回前面的内容

相关阅读 >>

nginx动静分离的好处

nginx和netty区别

nginx是什么意思

怎么解决nginx下php flush失效的问题

nginx怎么实现反向代理

nginx负载均衡数据库怎么做

深入 nginx 之配置篇

tengine和nginx哪个好

nginx如何实现动静分离

详解nginx高并发配置参数

更多相关阅读请进入《nginx》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...