nginx新增 echo模块

在nginx已经安装的情况下新增echo模块
1.下载需要新增的模块(升级nginx与此一样)
模块:v0.61.tar.gz

2.解压到与nginx包解压同级的目录

[root@nginx ~]# cd /usr/src/
[root@nginx src]# ls
debug  kernels  nginx-1.16.1  nginx-1.16.1.tar.gz  v0.61.tar.gz
[root@nginx src]# tar xf v0.61.tar.gz 
[root@nginx src]# ls
debug  echo-nginx-module-0.61  kernels  nginx-1.16.1  nginx-1.16.1.tar.gz  v0.61.tar.gz

3.进入nginx的解压目录

[root@nginx src]# cd nginx-1.16.1/

4.nginx -V 查看原有的编译选项并复制

[root@nginx nginx-1.16.1]# nginx -V
nginx version: nginx/1.16.1
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC) 
built with OpenSSL 1.0.2k-fips  26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --user=nginx --group=nginx --with-debug --with-http_ssl_module --with-http_realip_module --with-http_image_filter_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_stub_status_module --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log

5.重新配置与编译
./configure --add-module=…/新增模块目录
原有的编译选项

  [root@nginx nginx-1.16.1]# ./configure --add-module=/usr/src/echo-nginx-module-0.61 \
    --prefix=/usr/local/nginx \
    > --user=nginx \
    > --group=nginx \
    > --with-debug \
    > --with-http_ssl_module \
    > --with-http_realip_module \
    > --with-http_image_filter_module \
    > --with-http_gunzip_module \
    > --with-http_gzip_static_module \
    > --with-http_stub_status_module \
    > --http-log-path=/var/log/nginx/access.log \
    > --error-log-path=/var/log/nginx/error.log

6.编译好之后禁止make install,应该在objs里面找到你新编译的程序
make install会直接覆盖安装

[root@nginx nginx-1.16.1]# make
......
[root@nginx nginx-1.16.1]# ls
auto     CHANGES.ru  configure  html     Makefile  objs    src
CHANGES  conf        contrib    LICENSE  man       README
[root@nginx nginx-1.16.1]# cd objs/
[root@nginx objs]# ls
addon         Makefile  nginx.8            ngx_auto_headers.h  ngx_modules.o
autoconf.err  nginx     ngx_auto_config.h  ngx_modules.c       src

7.停止服务并备份原有的程序文件

[root@nginx ~]#nginx -s stop
[root@nginx ~]# cd /usr/local/nginx/sbin/
[root@nginx sbin]# ls
nginx
[root@nginx sbin]# mv nginx{,-A}
[root@nginx sbin]# ls
nginx-A

8.将新编译的程序文件替换原有的程序文件

[root@nginx sbin]# cp /usr/src/nginx-1.16.1/objs/nginx /usr/local/nginx/sbin/
[root@nginx sbin]# ls
nginx  nginx-A
[root@nginx sbin]# ll
总用量 12976
-rwxr-xr-x  1 root root 6948144 8月  28 10:42 nginx
-rwxr-xr-x. 1 root root 6335704 8月  28 01:57 nginx-A

9.启动nginx

[root@nginx ~]#nginx
[root@nginx sbin]# ss -antl
State      Recv-Q Send-Q Local Address:Port               Peer Address:Port              
LISTEN     0      128               *:111                           *:*                  
LISTEN     0      128               *:80                            *:*                  
LISTEN     0      5      192.168.122.1:53                            *:*                  
LISTEN     0      128               *:22                            *:*                  
LISTEN     0      128       127.0.0.1:631                           *:*                  
LISTEN     0      100       127.0.0.1:25                            *:*                  
LISTEN     0      128       127.0.0.1:6010                          *:*                  
LISTEN     0      128              :::111                          :::*                  
LISTEN     0      128              :::22                           :::*                  
LISTEN     0      128             ::1:631                          :::*                  
LISTEN     0      100             ::1:25                           :::*                  
LISTEN     0      128             ::1:6010                         :::*         

验证:

//在配置文件里修改location
[root@nginx ~]# vim /usr/local/nginx/conf/nginx.conf
location / {
            root   html;
            echo   'A';
            index  index.html index.htm;
        }


           location = /abc {
             echo 'B';
             root html;
             index index.html;
         }
         
//刷新配置文件
[root@nginx ~]# nginx -s reload              

//在另一个终端 192.168.176.112下打开   
[root@mysql ~]# curl http://192.168.176.111/abc
B
[root@mysql ~]# curl http://192.168.176.111/abcd
A
[root@mysql ~]# curl http://192.168.176.111/ab
A
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值