zoukankan      html  css  js  c++  java
  • nginx--第三方模块echo

      第三方模块是对nginx 的功能扩展,第三方模块需要在编译安装nginx 的时候使用参数--add-module=PATH指定路径添加,有的模块是由公司的开发人员针对业务需求定制开发的,有的模块是开源爱好者开发好之后上传到github进行开源的模块,nginx支持第三方模块,需要重新编译源码才能支持

    开源的echo模块,实现输出变量等信息:
    https://github.com/openresty/echo-nginx-module

      默认添加echo命令会提示错误

    location /test {
            echo "hello word";
    }
    [15:00:57 root@localhost conf.d]#nginx -t
    nginx: [emerg] "location" directive is not allowed here in /apps/nginx/conf.d/test.conf:2
    nginx: configuration file /apps/nginx/conf/nginx.conf test failed

      一、通过git命令下载源码.

        1、安装git命令

    yum install git -y

        2、

    cd /usr/local/src

        3、通过clone 将github上的站点抓取下来

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

    我这里抓取失败,在网上找到了其他办法,将https//xxxx改为git//xxxx

    git clone git://github.com/openresty/echo-nginx-module.git

        4、下载nginx源码包

    wget http://nginx.org/download/nginx-1.20.1.tar.gz

        5、创建nginx用户

    useradd -r -s /sbin/nologin nginx

        6、安装依赖包

    yum install gcc pcre-devel openssl-devel zlib-devel perl-ExtUtils-Embed -y

        7、解压缩nginx源码

    tar xf nginx-1.20.1.tar.gz

        8、进入nginx目录中

    cd nginx-1.20.1

        9、编译安装

    ./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-http_perl_module 
    --with-pcre 
    --with-stream 
    --with-stream_ssl_module 
    --with-stream_realip_module 
    --add-module=/usr/local/src/echo-nginx-module
    make && make install

        10、修改nginx主配置文件

    vim /apps/nginx/conf/nginx.conf
    location /echo {
                    default_type text/html;
                    echo hello;
                    echo $cookie_sessionid;
            }

    在server字段添加一行,echo hello 是用来测试的

        11、启动nginx服务

    sbin/nginx
    

        12、测试访问本机地址下的echo,是否成功,返回hello则成功

    1 curl 192.168.1.5/echo
    2 hello

        13、捕获cookie

    1 curl -b sessionid=123456 192.168.1.5/echo
    2 hello
    3 123456

    -b, --cookie STRING/FILE String or file to read cookies from (H)=读取cookie的字符串或文件(H)

    ------------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------- 博客均为个人笔记,无所追求,仅供参考~~~ QQ--2382990774
  • 相关阅读:
    Retrofit2源码分析
    Android8.0硬件加速的重绘流程
    Android单元测试
    rand5->rand7,rand7->rand10
    快速排序的随机化版本
    快速排序
    亦或实现交换
    在最坏情况下,找到n个元素中第二小的元素需要n+lgn-2次比较
    3*n/2时间内求出最大最小值
    基数排序
  • 原文地址:https://www.cnblogs.com/alexlv/p/14837336.html
Copyright © 2011-2022 走看看