Nginx新增Echo模块使用

Nginx新增Echo模块使用

在原来安装nginx基础上新增Echo模块需要在原版本Nginx源码包重新解压编译,但是不需要重新安装

nginx安装可参考:
点击这里

Echo模块源码包下载链接:

https://github.com/openresty/echo-nginx-module

查看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

[root@VM-0-6-centos mnt]# cd nginx-1.18.0/
[root@VM-0-6-centos nginx-1.18.0]# /usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.18.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC)
built with OpenSSL 1.0.2k-fips  26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_random_index_module --with-http_sub_module
[root@VM-0-6-centos nginx-1.18.0]#

安装Echo模块:

unzip echo-nginx-module-master.zip

给Nginx动态增加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

[root@VM-0-6-centos mnt]# cd nginx-1.18.0/
[root@VM-0-6-centos nginx-1.18.0]# ./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,这个千万别用安装语句,仅仅编译即可,生成主程序,将现有的主程序替换即可

[root@VM-0-6-centos nginx-1.18.0]# make

这里以成功将Echo模块加入

[root@VM-0-6-centos objs]# ./nginx -V
nginx version: nginx/1.18.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC) 
built with OpenSSL 1.0.2k-fips  26 Jan 2017
TLS SNI support enabled
configure arguments: --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
[root@VM-0-6-centos objs]# pwd
/mnt/nginx-1.18.0/objs

让新Nginx程序生效:

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

实操:

[root@VM-0-6-centos nginx-1.18.0]# cp /mnt/nginx-1.18.0/objs/nginx /usr/local/nginx/sbin/
cp: overwrite ‘/usr/local/nginx/sbin/nginx’? y
[root@VM-0-6-centos nginx-1.18.0]# 

已经成功拷贝

[root@VM-0-6-centos nginx-1.18.0]# /usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.18.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC) 
built with OpenSSL 1.0.2k-fips  26 Jan 2017
TLS SNI support enabled
configure arguments: --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
[root@VM-0-6-centos nginx-1.18.0]# 

#重新启动Nginx:

/usr/local/nginx/sbin/nginx 

Echo模块测试:

vim nginx.conf,编辑server

location /test {
	echo "user123";
}

curl测试

curl http://106.52.36.65/echo1

Echo输出内置变量:

location /test {
	echo $remote_addr;
}

变量定义与输出:

location /test {
	set $name user123;
	echo $name;
}

异步执行多location:

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

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

location /main {
      echo_reset_timer;
 
      echo_location_async /echo1;
      echo_location_async /echo2;
 
      echo "took $echo_timer_elapsed sec for total.";
}

同步执行多location:

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.";
}

echo_duplicate重复多次输出:

location /echo3 {
    echo_duplicate 10 "hello ";
}

猜你喜欢

转载自blog.csdn.net/weixin_39218464/article/details/112693439