Nginx 有个 echo 模块可以用来输出一些简单的信息,例如:

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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
location /hello {
  echo "hello, world!";
}
 
location /hello {
  echo -n "hello, "
  echo "world!";
}
 
location /timed_hello {
  echo_reset_timer;
  echo hello world;
  echo "'hello world' takes about $echo_timer_elapsed sec.";
  echo hiya igor;
  echo "'hiya igor' takes about $echo_timer_elapsed sec.";
}
 
location /echo_with_sleep {
  echo hello;
  echo_flush;  # ensure the client can see previous output immediately
  echo_sleep   2.5;  # in sec
  echo world;
}
 
# in the following example, accessing /echo yields
#   hello
#   world
#   blah
#   hiya
#   igor
location /echo {
    echo_before_body hello;
    echo_before_body world;
    proxy_pass $scheme://127.0.0.1:$server_port$request_uri/more;
    echo_after_body hiya;
    echo_after_body igor;
}
location /echo/more {
    echo blah;
}
 
# the output of /main might be
#   hello
#   world
#   took 0.000 sec for total.
# and the whole request would take about 2 sec to complete.
location /main {
    echo_reset_timer;
 
    # subrequests in parallel
    echo_location_async /sub1;
    echo_location_async /sub2;
 
    echo "took $echo_timer_elapsed sec for total.";
}
location /sub1 {
    echo_sleep 2;
    echo hello;
}
location /sub2 {
    echo_sleep 1;
    echo world;
}
 
# the output of /main might be
#   hello
#   world
#   took 3.003 sec for total.
# and the whole request would take about 3 sec to complete.
location /main {
    echo_reset_timer;
 
    # subrequests in series (chained by CPS)
    echo_location /sub1;
    echo_location /sub2;
 
    echo "took $echo_timer_elapsed sec for total.";
}
location /sub1 {
    echo_sleep 2;
    echo hello;
}
location /sub2 {
    echo_sleep 1;
    echo world;
}
 
# Accessing /dup gives
#   ------ END ------
location /dup {
  echo_duplicate 3 "--";
  echo_duplicate 1 " END ";
  echo_duplicate 3 "--";
  echo;
}
 
# /bighello will generate 1000,000,000 hello's.
location /bighello {
  echo_duplicate 1000_000_000 'hello';
}
 
# echo back the client request
location /echoback {
  echo_duplicate 1 $echo_client_request_headers;
  echo "\r";
 
  echo_read_request_body;
 
  echo_request_body;
}
 
# GET /multi will yields
#   querystring: foo=Foo
#   method: POST
#   body: hi
#   content length: 2
#   ///
#   querystring: bar=Bar
#   method: PUT
#   body: hello
#   content length: 5
#   ///
location /multi {
    echo_subrequest_async POST '/sub' -q 'foo=Foo' -b 'hi';
    echo_subrequest_async PUT '/sub' -q 'bar=Bar' -b 'hello';
}
location /sub {
    echo "querystring: $query_string";
    echo "method: $echo_request_method";
    echo "body: $echo_request_body";
    echo "content length: $http_content_length";
    echo '///';
}
 
# GET /merge?/foo.js&/bar/blah.js&/yui/baz.js will merge the .js resources together
location /merge {
    default_type 'text/javascript';
    echo_foreach_split '&' $query_string;
        echo "/* JS File $echo_it */";
        echo_location_async $echo_it;
        echo;
    echo_end;
}
 
# accessing /if?val=abc yields the "hit" output
# while /if?val=bcd yields "miss":
location ^~ /if {
    set $res miss;
    if ($arg_val ~* '^a') {
        set $res hit;
        echo $res;
    }
    echo $res;
}

这个模块不包含在 Nginx 源码中,安装方法:

1. 首先下载模块源码:https://github.com/agentzh/echo-nginx-module/tags
2. 解压到某个路径,假设为 /path/to/echo-nginx-module
3. 使用下面命令编译并安装 Nginx

1
2
3
4
5
6
7
8
9
10
$ wget 'http://sysoev.ru/nginx/nginx-1.0.11.tar.gz'
$ tar -xzvf nginx-1.0.11.tar.gz
$ cd nginx-1.0.11/
 
# Here we assume you would install you nginx under /opt/nginx/.
$ ./configure --prefix=/opt/nginx \
--add-module=/path/to/echo-nginx-module
 
$ make -j2
$ make install

试试看吧,该模块是国人 @章亦春 开发的。

http://www.oschina.net/question/12_45735?fromerr=jyurMByB

Nginx 的 Echo 模块 —— echo-nginx-module(转)的更多相关文章

  1. nginx安装第三方模块echo

    要使用第三方模块ngx_echo的功能,请重新配置添加到nginx插件中 ##下载第三方模块 wget https://github.com/openresty/echo-nginx-module/a ...

  2. nginx 安装 lua_nginx_module 模块(nginx——lua 学习笔记1)

    插入两个网站: nginx + lua 的OpenResty 开发 跟我学OpenResty(Nginx+Lua)开发目录贴 两个都是 可以根据目录一步步学习的. 1. 版本下载 nginx版本为 n ...

  3. nginx之echo模块与内置变量

    Nginx扩展第三方模块——echo 第三方模块是对nginx的功能扩展,第三方模块需要在编译nginx的时候使用参数--add-module=PATH指定扩展模块的源码包路径给Nginx扩展添加ec ...

  4. Nginx 编译 echo 模块

    Nginx  编译 echo 模块 echo模块下载地址:https://github.com/openresty/echo-nginx-module 查看nginx已经编译的模块, nginx -V ...

  5. Nginx SPDY Pagespeed模块编译——加速网站载入

    在看<Web性能权威指南>的时候,看到了SPDY这货,于是便开始折腾起了这个了,也顺便把pagespeed加了进去. Nginx SPDY 引自百科~~ SPDY(读作“SPeeDY”)是 ...

  6. Nginx访问限制模块limit_conn_zone 和limit_req_zone配置使用

    nginx可以通过limit_conn_zone 和limit_req_zone两个组件来对客户端访问目录和文件的访问频率和次数进行限制,另外还可以善用进行服务安全加固,两个模块都能够对客户端访问进行 ...

  7. Nginx详解二十三:Nginx深度学习篇之Nginx+Lua开发环境搭建

    Nginx+Lua开发环境 1.下载LuaJIT解释器wget http://luajit.org/download/LuaJIT-2.0.2.tar.gztar -zxvf LuaJIT-2.0.2 ...

  8. Nginx安装echo模块

    echo-nginx-module 模块可以在Nginx中用来输出一些信息,可以用来实现简单接口或者排错. 项目地址:https://github.com/openresty/echo-nginx-m ...

  9. Aliyun OSS Nginx proxy module(阿里云OSS Nginx 签名代理模块)

    1.此文章主要介绍内容 本文主要介绍如何利用Nginx lua 实现将阿里云OSS存储空间做到同本地磁盘一样使用.核心是利用Nginx lua 对OSS请求进行签名并利用内部跳转将所有访问本地Ngin ...

随机推荐

  1. Spring学习之Jar包功能介绍(转)

    spring.jar 是包含有完整发布模块的单个jar 包.但是不包括mock.jar, aspects.jar, spring-portlet.jar, and spring-hibernate2. ...

  2. C# Excel或表格插件

    NOPI好像比较好用对WINFORM支持更好! http://www.cnblogs.com/dreamof/archive/2010/06/02/1750151.html NOPI教程 http:/ ...

  3. php框架

    使用composer构建的php框架 github: https://github.com/Ev2le0/LeoFramework 实现功能: 1)路由 2)ORM 3)视图

  4. 求模和求余(附加C语言实现)

    求模和求余的总体计算步骤如下: 1.求整数商  c = a/b 2.计算模或者余数 r = a - c*b 求模和求余的第一步不同,求余在取c的值时向0方向舍入;取模在计算c的值时向无穷小方向舍入. ...

  5. Linux Apache绑定多域名

    1 网上查到资源不符 网上查到的Apache绑定域名都说要修改http.conf文件,但是我的服务器上的apache是通过apt-get install安装的,安装方法应该是没错的,但是通过find ...

  6. CodeForces 22C System Administrator

    把v和2结点交换, 1和v连,其它点和v之间能够互相连. #include <iostream> #include <cstdlib> #include <cstring ...

  7. 图片变灰css3

    -webkit-filter: grayscale(100%); -moz-filter: grayscale(100%); -ms-filter: grayscale(100%); -o-filte ...

  8. Jquery 方法大全

    一.JQuery常用的方法 :(JQuery中90%都是方法,没有参数是获取,带参数是设置) $("#id").css('backgroundColor','blue'); .cs ...

  9. subversion和客户端的应用

    1.安装svn的服务器端subversion.以及windows客户端TortoiseSVN: 2 cmd 建立库,名字为svnpro ----- svnadmin create F:\svnpro, ...

  10. Android应用开发基础篇(12)-----Socket通信

    链接地址:http://www.cnblogs.com/lknlfy/archive/2012/03/03/2378669.html 一.概述 网络通信无论在手机还是其他设备上都应用得非常广泛,因此掌 ...