Nginx 调试模块 echo-nginx-module

引言

Nginx 作为一个高性能的 HTTP 和反向代理 Web 服务器。如今很多项目都会选择 Nginx 作为反向代理服务器,但是避免不了在使用的过程中,会遇到各种各样的问题。因此 echo-nginx-module 专门针对 Nginx 的调试模块诞生了,下面就简单的介绍一下它的安装与使用方法。

安装

这里是已经提前安装过 Nginx的,如果还未安装的,请提前安装。

1、配置需要编译的额外模块。

ubuntu@VM-0-10-ubuntu:~/nginx-1.9.9$ ./configure --prefix=/opt/nginx --add-module=--prefix=/home/ubuntu/nginx --add-module=/home/ubuntu/echo-nginx-module 

2、开始编译,这里的 -j2 指的是:在多 CPU 上并行编译,加快编译速度。

make -j2

3、编译安装。

make install

注:如果在编译安装过程中报错,可参考文章:https://blog.csdn.net/qq_30505673/article/details/82387313。

开始使用

编辑 /home/ubuntu/nginx/conf/nginx.conf 文件

ubuntu@VM-0-10-ubuntu:~/nginx$ vim conf/nginx.conf

写一段测试代码

重启 Nginx 服务

ubuntu@VM-0-10-ubuntu:~/nginx$ sudo ./sbin/nginx -s reload

访问测试地址 http://localhost/test 输出了我们加入的 Hello World!。

ubuntu@VM-0-10-ubuntu:~/nginx$ curl http://localhost/test
Hello World!

进阶用法

输出当前请求路径

location /test {
    echo "request uri:" $request_uri;
}

访问测试

ubuntu@VM-0-10-ubuntu:~/nginx$ curl http://localhost/test
request uri: /test

输出请求头信息

location /test {
    echo_duplicate 1 $echo_client_request_headers;
}

访问测试

ubuntu@VM-0-10-ubuntu:~/nginx$ curl http://localhost/test
GET /test HTTP/1.1
Host: localhost
User-Agent: curl/7.58.0
Accept: */*

官方文档

原文地址:https://www.cnblogs.com/yxhblogs/p/12901575.html