1.下载模块

git clone https://github.com/agentzh/echo-nginx-module

2.放入指定位置

mv echo-nginx-module-master /usr/local/src/nginx-1.8.1/echo-nginx-module

3.查看已编译参数

/usr/local/nginx/sbin/nginx -V   结果为:
--user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-ipv6

4.重新编译

./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --add-module=/usr/local/src/nginx-1.8.1/echo-nginx-module --with-ipv6 
make

PS: 这里只需要make,一定不要执行make install,不然会覆盖

5.备份原文件

cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak

6.替换nginx二进制文件

cp /usr/local/src/nginx-1.8.1/objs/nginx /usr/local/nginx/sbin/nginx

7.检查以及平滑启动nginx

ln -s /usr/local/nginx/sbin/nginx /usr/local/bin/nginx(做软链,添加到环境变量)
nginx -t (检测配置文件)
nginx -s reload (平滑重启)

 转自:https://www.cnblogs.com/654wangzai321/p/8000780.html