在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