Open the Echo-nginx-module module record on the Nginx 1.12.2 of CentOS 6.9 x86_64

Source: Internet
Author: User
Tags curl openssl centos git clone
Echo-nginx-module is a third-party module, not in Nginx source code, but in Openresty, it brings echo,sleep,time and other powerful commands like bash for nginx.conf.
Currently the latest version is v0.61

Installation Guide See
Https://github.com/openresty/echo-nginx-module#installation

Configuration

    server {
        listen 8081;
        server_name localhost;

        location/test {
            set $foo hello;
            echo "foo: $foo";
        }

        Location/test1 {
            set $first "Hello";
            echo "${first}world";
        }

        Location/foo {
            echo "foo = [$foo]";
        }

        Location/bar {
            set $foo; 
            echo "bar = [$foo]";
        }
    }   
The complete nginx.conf is as follows:
Https://github.com/taoyunxing/github_test/blob/master/nginx.conf

Download source code
Cd/usr/local/src
git clone https://github.com/openresty/echo-nginx-module.git

CD nginx-1.12.2
./configure--with-http_ssl_module \
--with-pcre=/usr/local/src/pcre-8.41 \
--with-zlib=/usr/local/src/zlib-1.2.11 \
--with-openssl=/usr/local/src/openssl-1.1.0g \
--with-http_stub_status_module \
--add-module=/usr/local/src/ngx_cache_purge \
--add-module=/usr/local/src/ngx_req_status \
--add-module=/usr/local/src/echo-nginx-module
Make
Make install

This example also shows how the modules in Openresty are compiled into the latest version of Nginx in the community. I initially saw the Openresty in the module directory is more strange, I think it is necessary to adjust the directory structure and then integrated into Nginx, in fact, there is no need.

After the installation is complete, check the integrity of the nginx.conf and restart Nginx
/usr/local/nginx/sbin/nginx-t
/usr/local/nginx/sbin/nginx-s stop
/usr/local/nginx/sbin/nginx

Test request
Curl-v ' Http://localhost:8081/test '


Curl-v ' Http://localhost:8081/test1 '


Curl-v ' Http://localhost:8081/foo '


Curl-v ' Http://localhost:8081/bar '

Special Instructions

The above is only the most basic usage, there are many high-level usage to be further explored when further added.

Here's what to add.

    server {
        listen 8082;
        server_name localhost;

        Location/foo {
            set $a hello;
            Echo_exec/bar;
        }

        location/foo1 {
            set $a hello;
            rewrite ^/bar;
        }

        Location/bar {
            echo "a = [$a]";
        }
    }   
After updating nginx.conf, perform the following command to check

Curl-v ' Http://localhost:8082/foo '


Curl-v ' Http://localhost:8082/foo1 '


Here's a further example.

Because the modification of the built-in variable $args directly causes the URL parameter string of the current request to change, the built-in variable $arg _xxx will naturally change as well.

    LOCATION/TEST3 {
        set $orig _a $arg _a;
        Set $args "a=5";
        Echo "Original A: $orig _a";
        echo "A: $arg _a";
    }
Curl ' http://localhost:8082/test3?a=3 '


    server {
        listen 8083;
        server_name localhost;
 
        location/test {
            set $args "foo=1&bar=2";
            Proxy_pass Http://127.0.0.1:8084/args;
        }
    }
 
    server {
        listen 8084;
        server_name localhost;

        Location/args {
            echo "args: $args";
        }
    }
Curl-v ' http://localhost:8083/test?blah=7 '


Variable sharing between parent and child requests

    Location/main {
        echo_location/foo2;
        echo_location/bar2;
    }
 
    Location/foo2 {
        echo foo2;
    }
 
    LOCATION/BAR2 {
        echo bar2;
    }
Curl ' Http://localhost:8082/main '

    location/main3 {
        set $var main;
        Echo_location/foo3;
        ECHO_LOCATION/BAR3;
        echo "main: $var";
    }
 
    Location/foo3 {
        set $var foo;
        echo "foo: $var";
    }
 
    LOCATION/BAR3 {
        set $var bar;
        echo "bar: $var";
    }

Curl-v ' http://localhost:8082/main3 '


Reference documents
[1].https://github.com/openresty/echo-nginx-module
[2].http://blog.sina.com.cn/s/blog_6d579ff40100wi7p.html


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.