Nginx动态增加Echo模块与使用

Nginx动态增加Echo模块

查看Nginx编译模块:

/usr/local/nginx/sbin/nginx -V
--prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_random_index_module --with-http_sub_module

安装Echo模块:

#下载地址
https://github.com/openresty/echo-nginx-module

unzip echo-nginx-module-master.zip

给Nginx动态增加Echo模块:(add 增加echo模块)

cd /mnt/nginx-1.17.5
# 执行以下命令在原有模块下动态增加echo模块
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_random_index_module --with-http_sub_module --add-module=/mnt/echo-nginx-module-master

把Nginx重新编译:(make生成主程序,不需要make install)

cd /mnt/nginx-1.17.5
make

查看编译模块是否添加成功

/mnt/nginx-1.17.5/objs/nginx -V

让新Nginx程序生效:

pkill nginx
cp /mnt/nginx-1.17.5/objs/nginx /usr/local/nginx/sbin/

重新启动Nginx:

/usr/local/nginx/sbin/nginx 

Echo模块使用

1、Echo模块测试:

location /test {
	echo "user123";
}
#验证
curl 192.168.56.10/test

2、Echo输出内置变量:

location /test {
	echo $remote_addr;
}
#验证
curl 192.168.56.10/test

3、变量定义与输出:

location /test {
	set $name user123;
	echo $name;
}
#验证
curl 192.168.56.10/test

4、异步执行多location:

location /echo1 {
    echo_sleep 1;
    echo '111';
}

location /echo2 {
    echo_sleep 1;
    echo '222';
}

#异步执行echo1、echo2


location /main {
      echo_reset_timer;
 
      echo_location_async /echo1;
      echo_location_async /echo2;
 
      echo "took $echo_timer_elapsed sec for total.";
}
#验证
curl 192.168.56.10/main 

5、同步执行多location:(当echo1未执行完成,echo2只能等待)

location /echo1 {
    echo_sleep 1;
    echo '111';
}

location /echo2 {
    echo_sleep 2;
    echo '222';
}

location /main {
      echo_reset_timer;
 
      echo_location /echo1;
      echo_location /echo2;
 
      echo "took $echo_timer_elapsed sec for total.";
}
#验证
curl 192.168.56.10/main

6、echo_duplicate重复多次输出:

location /echo3 {
    echo_duplicate 10 "hello ";
}
#验证
curl 192.168.56.10/echo3
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值