echo-nginx-module 模块可以在Nginx中用来输出一些信息,可以用来实现简单接口或者排错。

项目地址:https://github.com/openresty/echo-nginx-module

获取Nginx源码

因为需要编译模块,需要有Nginx源码。

如果已安装Nginx,需要查看当前安装版本的编译参数:

$ /usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.12.2
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-18) (GCC)
built with OpenSSL 1.0.1e-fips 11 Feb 2013
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module --with-http_sub_module --with-http_gzip_static_module

其中configure arguments这个参数是非常重要的,我们在后面安装Lua模块的时候,需要以这个为基础,增加新的参数。

如果还没有安装Nginx,上面可以忽略。

Nginx下载页面:http://nginx.org/en/download.html

这里我们以 nginx/1.12.2 为例。需要获取源码:

$ cd /opt/
$ wget http://nginx.org/download/nginx-1.12.2.tar.gz
$ tar -zxvf nginx-1.12.2.tar.gz

安装取echo-nginx-module

获取echo-nginx-module

我们下载最新稳定版(截止到2018-12-23),并解压,不用安装:

$ cd /opt
$ wget https://github.com/openresty/echo-nginx-module/archive/v0.61.tar.gz
$ tar zxvf v0.61.tar.gz

编译Nginx

Nginx编译参数配置:

$ cd /opt/nginx-1.12.2/
$ ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module --with-http_sub_module --with-http_gzip_static_module --add-module=/opt/echo-nginx-module-0.61

这里因为已经安装了Nginx,所以这里的参数是从Nginx -V的输出里获取的,并追加了新的参数:

--add-module=/opt/echo-nginx-module-0.61

运行上面的./configure后进行编译安装:

$ make -j2
$ make install

make install后,会覆盖之前安装的Nginx。

测试echo模块

/usr/local/nginx/conf/nginx.confserver代码块里加入如下代码:

location /hello {
default_type 'text/plain';
return 200 'hello!';
} location /hello_echo {
default_type 'text/plain';
echo "hello, echo!";
}

注意:重新编译 Nginx 二进制,Nginx 需要停止重启。而普通配置更新则 reload 即可:

$ kill -QUIT `cat /usr/local/nginx/logs/nginx.pid` && /usr/local/nginx/sbin/nginx

如果支持service nginx restart,则可以这样重新启动:

$ service nginx restart && /usr/local/nginx/sbin/nginx -s reload

然后curl测试:

$ curl http://127.0.0.1/hello
hello! $ curl http://127.0.0.1/hello_echo
hello, echo!

当然, echo-nginx-module 模块不仅仅是提供echo这么简单的指令,还有其它的指令,详见:https://github.com/openresty/echo-nginx-module#content-handler-directives

编译动态模块

echo-nginx-module 支持以动态模块方式加载,详见:https://github.com/openresty/echo-nginx-module#installation 。Nginx版本需要 >=1.9.11

$ cd /opt/nginx-1.12.2/
$ ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module --with-http_sub_module --with-http_gzip_static_module --add-dynamic-module=/opt/echo-nginx-module-0.61 $ make -j2
$ make install

相比静态编译,参数--add-module改成了--add-dynamic-module

编译成功后,会把模块安装在nginx/modules/目录。查看:

$ ls /usr/local/nginx/modules/
ngx_http_echo_module.so

接下来我们需要在nginx.conf配置中加入以下两行,实现动态调用模块:

load_module /usr/local/nginx/modules/ngx_http_echo_module.so;

注意:load_module指令不能放在 http{} 里面:

worker_processes  1;

load_module xxx;

#error_log  logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info; #pid logs/nginx.pid; events {
worker_connections 1024;
} http { }

接下来可以按上面的 测试echo模块 小节测试。唯一不同的是无需使用kill -QUIT退出Nginx,直接使用nginx -s reload热重启就行了。

参考

1、Nginx安装Nginx-echo模块 - chen2013 - 博客园

http://www.cnblogs.com/chenjianxiang/p/8489055.html

2、openresty/echo-nginx-module

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

3、Nginx编译安装Lua - 飞鸿影~ - 博客园

https://www.cnblogs.com/52fhy/p/10164553.html

Nginx安装echo模块的更多相关文章

  1. Nginx安装echo模块echo-nginx-module

    https://github.com/openresty/echo-nginx-module 这个模块不包含在 Nginx 源码中,安装方法: 1. 首先下载模块源码:https://github.c ...

  2. nginx 安装echo模块

    学习资源: https://www.cnblogs.com/xwupiaomiao/p/7997938.html https://blog.csdn.net/hb1707/article/detail ...

  3. nginx 安装第三方模块(lua)并热升级

    需求: nginx上将特定请求拒绝,并返回特定值. 解决办法: 使用lua脚本,实现效果. 操作步骤: 安装Luajit环境 重新编译nginx(目标机器上nginx -V 配置一致,并新增两个模块n ...

  4. Nginx 编译 echo 模块

    Nginx  编译 echo 模块 echo模块下载地址:https://github.com/openresty/echo-nginx-module 查看nginx已经编译的模块, nginx -V ...

  5. nginx 安装第三方 模块

    查看nginx在安装时开启了哪些模块 如果你nginx是rpm包安装的,直接用如下命令nginx -V 如果你是源码包编译安装,假如你的安装路径是/usr/local/nginx,那么你可以使用: / ...

  6. Nginx 的 Echo 模块 —— echo-nginx-module(转)

    Nginx 有个 echo 模块可以用来输出一些简单的信息,例如: ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 2 ...

  7. Nginx安装Nginx-echo模块

    Nginx-echo可以在Nginx中用来输出一些信息,是在测试排错过程中一个比较好的工具.它也可以做到把来自不同链接地址的信息进行一个汇总输出.总之能用起来可以给开发人员带来挺大帮助的.下面看看我们 ...

  8. nginx安装lua-nginx-module模块

    转载注明地址:http://www.cnblogs.com/dongxiao-yang/p/5312285.html 本文主要采用手动源码安装的方式将lua-nginx模块编译到nginx源码内部 一 ...

  9. nginx安装第三方模块

    原已经安装好的nginx,现在需要添加一个未被编译安装的模块 举例说明:安装第三方的ngx_cache_purge模块(用于清除指定URL的缓存) nginx的模块是需要重新编译nginx,而不是像a ...

随机推荐

  1. 【Selenium】【BugList11】启动selenium server报错:Unsupported major.minor version 52.0

    [环境信息] python:3.6.5 平台:win7 selenium:3.11.0 selenium server:selenium-server-standalone-3.11.0.jar jd ...

  2. php中的问题整理

    1.什么是 CSRF 攻击 ?XSS 攻击?如何防范? CSRF,跨站请求伪造,攻击方伪装用户身份发送请求从而窃取信息或者破坏系统.讲述基本原理:用户访问A网站登陆并生成了cookie,再访问B网站, ...

  3. Unity3D编辑器扩展(四)——扩展自己的组件

    前面已经写了三篇: Unity3D编辑器扩展(一)——定义自己的菜单按钮 Unity3D编辑器扩展(二)——定义自己的窗口 Unity3D编辑器扩展(三)——使用GUI绘制窗口 今天写第四篇,扩展自己 ...

  4. Spring使用Autowiring自动装配 解决提示报错小技巧

    1.打开Settings   输入Inspections  找到Spring --> Spring Core --> Code --> Autowiring  for  Bean  ...

  5. java.exe

    进程:是一个正在执行中的程序.每一个进程执行都有一个执行顺序.该顺序是一个执行路径,或者叫一个控制单元. 线程(例:FlashGet):就是进程中一个独立的控制单元.线程在控制着进程的执行.一个进程中 ...

  6. UITableViewCell上放UICollectionView ,UICollectionViewCell无法复用bug

    如题: UITableViewCell上放UICollectionView ,UICollectionViewCell无法复用bug 如果UITableViewCell的size大于整个collect ...

  7. SpringBoot 通过 Exploded Archives 的方式部署

    之前部署 SpringBoot 一直是用可执行 jar 的方式. java -jar codergroup-1.0.0.jar 就可以启动项目,为了能在后台运行,通常我们会使用这行命令 nohup j ...

  8. Java 判断两个对象是否相等

    一.使用 == 与 equals == : 它的作用是判断两个对象的地址是不是相等.即,判断两个对象是不是同一个对象.(基本数据类型==比较的是值,引用数据类型==比较的是内存地址) equals() ...

  9. 聊一聊Java如何接入招行一网通支付功能

    1.前提条件 相比较于支付宝和微信的支付功能接入这一块,银行相对来说更加严格,比如说支付宝,在你签约之前可以进行一些测试.但是银行来说就不是这样了,如果您现在要进行招行的支付功能开发的话,请务必先让相 ...

  10. Android7.0适配APK安装

    Android7.0适配APK安装 适配的原因 对于面向Android7.0的应用,Android框架执行的StrictMode API政策禁止在您的应用外部公开file://URL.如果一项包含文件 ...