Nginx 三方模块 echo 的加载和使用

3.1.1:echo 模块

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

克隆
  • 安装 git:
[root@node106 ~]# yum install git -y
  • 从 github 克隆echo模块:
[root@node106 ~]# cd /usr/local/src
[root@node106 src]# git clone https://github.com/openresty/echo-nginx-module.git

[root@node106 src]# ll echo-nginx-module/
total 76
-rw-r--r-- 1 root root  3184 Dec  2 16:33 config
-rw-r--r-- 1 root root  1345 Dec  2 16:33 LICENSE
-rw-r--r-- 1 root root 54502 Dec  2 16:33 README.markdown
drwxr-xr-x 2 root root  4096 Dec  2 16:33 src
drwxr-xr-x 2 root root  4096 Dec  2 16:33 t
drwxr-xr-x 2 root root    52 Dec  2 16:33 util
-rw-r--r-- 1 root root   986 Dec  2 16:33 valgrind.suppress
重新编译安装 Nginx
  • 查看 nginx 之前的编译参数:
[root@node106 ~]# nginx -V
nginx version: nginx/1.18.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) 
built with OpenSSL 1.0.2k-fips  26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/apps/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre --with-stream --with-stream_ssl_module --with-stream_realip_module
[root@node106 ~]#
  • 添加 echo 模块,重新生成 Makefile:
[root@node106 ~]# cd /usr/local/src/nginx-1.18.0/

[root@node106 nginx-1.18.0]# ./configure \
--prefix=/apps/nginx \
--user=nginx --group=nginx \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_realip_module \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--with-pcre \
--with-stream \
--with-stream_ssl_module \
--with-stream_realip_module \
--add-module=/usr/local/src/echo-nginx-module
  • 重新编译安装 nginx:
[root@node106 nginx-1.18.0]# make && make install
测试 echo 模块
  • 编译配置文件:
server {
  listen 192.168.1.106:80;
  server_name www.yqc.com;
  error_page 500 502 503 504 404 /error.html;
  access_log /data/nginx/logs/www-yqc-com_access.log;
  error_log /data/nginx/logs/www-yqc-com_error.log;
  location / {
    root /data/nginx/yqc/www;
    index index.html;
  }

  location = /error.html {
    root /data/nginx/yqc/redirect;
  }

  location = /status {
    stub_status;
    allow 192.168.1.0/24;
    allow 127.0.0.1;
    deny all;
  }

  location /main {
    index index.html;
    default_type text/html;
    echo "hello world,main-->";
    echo_reset_timer;
    echo_location /sub1;
    echo_location /sub2;
    echo "took $echo_timer_elapsed sec for total.";
  }

  location /sub1 {
    echo_sleep 1;
    echo sub1;
  }

  location /sub2 {
    echo_sleep 1;
    echo sub2;
  }
}
  • 检查配置文件并重启nginx:
[root@node106 ~]# nginx -t
nginx: the configuration file /apps/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /apps/nginx/conf/nginx.conf test is successful
[root@node106 ~]# systemctl restart nginx

新装模块需要重启生效;

  • 访问测试:
[root@node105 ~]# curl http://www.yqc.com/main
hello world,main-->
sub1
sub2
took 2.003 sec for total.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值