The Echo module of Nginx--echo-nginx-module

Source: Internet
Author: User

Nginx has an echo module that can be used to output some simple information, such as:

?
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 6667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611 7118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 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#   igorlocation /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 requestlocation /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 togetherlocation /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;}

This module is not included in the Nginx source code, the installation method:

1. First download Module source code: Https://github.com/agentzh/echo-nginx-module/tags
2. Extract to a path, assuming/path/to/echo-nginx-module
3. Use the command below to compile and install Nginx

?
12345678910 $ 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

Try it, this module is also the spring development of the Chinese People @ Chapter.

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

Nginx Echo Module--echo-nginx-module (ext.)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.