(添加echo模块)配置
1.先去github或者gitee中找到nginx_module_echo-master.zip包
2.将原来的ngin-1.20.1删除,重新编译安装
[root@host src]# ls
debug kernels nginx-1.20.1.tar.gz wujunze-nginx_module_echo-master.zip
[root@host src]# yum -y install unzip
[root@host src]# unzip wujunze-nginx_module_echo-master.zip
Archive: wujunze-nginx_module_echo-master.zip
cc5135fd7a7c87ccac48fd05509396443c71c065
creating: nginx_module_echo/
extracting: nginx_module_echo/.gitignore
inflating: nginx_module_echo/LICENSE
inflating: nginx_module_echo/README.md
inflating: nginx_module_echo/README_zh.md
inflating: nginx_module_echo/config
creating: nginx_module_echo/src/
inflating: nginx_module_echo/src/ngx_http_echo_module.c
[root@host src]# tar xf nginx-1.20.1.tar.gz
[root@host src]# ls
debug kernels nginx-1.20.1 nginx-1.20.1.tar.gz nginx_module_echo wujunze-nginx_module_echo-master.zip
- 查看之前的安装配置
[root@host ~]# nginx -V
nginx version: nginx/1.20.1
built by gcc 8.5.0 20210514 (Red Hat 8.5.0-2) (GCC)
built with OpenSSL 1.1.1k FIPS 25 Mar 2021
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
- 开始编译安装
[root@host nginx-1.20.1]# ./configure --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 --add-module=../nginx_module_echo
可以发现现在多了一个objs目录
[root@host nginx-1.20.1]# ls
auto CHANGES CHANGES.ru conf configure contrib html LICENSE Makefile man objs README src
[root@host nginx-1.20.1]# make
[root@host nginx-1.20.1]# ls objs/
addon autoconf.err Makefile ngx_auto_config.h ngx_auto_headers.h ngx_modules.c src
[root@host nginx-1.20.1]# ls objs/
addon Makefile nginx.8 ngx_auto_headers.h ngx_modules.o
autoconf.err nginx ngx_auto_config.h ngx_modules.c src
替换nginx文件
[root@host nginx-1.20.1]# pkill nginx;\cp objs/nginx /usr/local/nginx/sbin/;nginx
[root@host nginx-1.20.1]# nginx -V
nginx version: nginx/1.20.1
built by gcc 8.5.0 20210514 (Red Hat 8.5.0-2) (GCC)
built with OpenSSL 1.1.1k FIPS 25 Mar 2021
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 --add-module=../nginx_module_echo
location应用
修饰符 | 功能 |
---|---|
= | 精确匹配 |
~ | 正则表达式模式匹配,区分大小写 |
~* | 正则表达式模式匹配,不区分大小写 |
^~ | 前缀匹配,类似于无修饰符的行为,也是以指定模块开始,不同的是,如果模式匹配,那么就停止搜索其他模式了,不支持正则表达式 |
@ | 定义命名location区段,这些区段客户端不能访问,只可以由内部产生的请求来访问,如try_files或error_page等 |
- ( location = 路径 ) --> ( location ^~ 路径 ) --> ( location ~ 正则 ) --> ( location ~* 正则 ) --> ( location 路径 )
[root@host ~]# vim /usr/local/nginx/conf/nginx.conf
......
location /abc {
echo "hehe";
}
#error_page 404 /404.html;
......
用windows的cmd查看
精确查找
[root@host ~]# vim /usr/local/nginx/conf/nginx.conf
......
location = /abc {
echo "hehe";
}
......
正则表达式模式匹配,区分大小写
[root@host ~]# vim /usr/local/nginx/conf/nginx.conf
......
location ~ /abc {
echo "hehe";