Install Nginx-echo module in Nginx

Source: Internet
Author: User

Install Nginx-echo module in Nginx

Nginx-echo can be used to output some information in Nginx. It is a good tool for testing troubleshooting. It can also make a summary of the information from different link addresses. In short, it can help developers. Next let's take a look at how to install and use it.

1. Download Nginx-echo

Cd/usr/local/nginx-1.12.2/
Wget https://github.com/openresty/echo-nginx-module/archive/v0.60.tar.gz

2. decompress the downloaded file

Tar zxvf v0.60.tar.gz

3. Check the previously installed modules.

/Usr/local/nginx/sbin/nginx-V

4. Go to the Nginx installation package directory that was previously downloaded to configure

Cd/usr/local/nginx-1.12.2/
./Configure -- add-module =/usr/local/nginx-1.12.2/echo-nginx-module-0.61 -- add-module =/usr/local/nginx-1.12.2/ngx_image_thumb-master

5. Compile and install the SDK. For upgrade, you can use make upgrade.

Make & make install

6. Using echo, the following content is an official case and I have added my own understanding.

# Simple output: the log address of others is/hello. I don't know why I haven't been able to access it after testing, so add/
Location/hello /{
Echo "hello, world! ";
}

# $ Echo_timer_elapsed timing, which starts computing after being executed by echo_reset_timer
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 .";
}

# Echo_sleep can be output after 2.5s
Location/echo_with_sleep /{
Echo hello;
Echo_flush; # ensure the client can see previous output immediately
Echo_sleep 2.5; # in sec
Echo world;
}

# Add the specified content before and after the source code obtained by the proxy_pass address
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;
}

# Echo_location_async can access other addresses asynchronously without affecting the execution of the current function. The final output value of $ echo_timer_elapsed is 0.
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;
}

# Synchronous execution
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;
}

# Echo_duplicate 3 "--" means repeated output three times "--"
Location/dup /{
Echo_duplicate 3 "--";
Echo_duplicate 1 "END ";
Echo_duplicate 3 "--";
Echo;
}


# Output client request information
Location/echoback /{
Echo_duplicate 1 $ echo_client_request_headers;
Echo "\ r ";
 
Echo_read_request_body;
Echo_request_body;
}

# Output querystring, method, body, content, and other information
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 '///';
}

# Merge multiple JavaScript codes into one URL for output
# 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;
}

# If the address is/if /? Val = abcd, then output hit
# The parameter name is val. The parameter value starts with.
Location/if /{
Set $ res miss;
If ($ arg_val ~ * '^ '){
Set $ res hit;
Echo $ res;
}
Echo $ res;
}

This article permanently updates link: https://www.bkjia.com/Linux/2018-03/151200.htm

Related Article

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.