3.1.1:echo 模块
https://github.com/openresty/echo-nginx-module
克隆
- 安装 git:
[root@node106 ~]# yum install git -y
- 从 github 克隆echo模块:
[root@node106 ~]# cd /usr/local/src
[root@node106 src]# git clone https://github.com/openresty/echo-nginx-module.git
[root@node106 src]# ll echo-nginx-module/
total 76
-rw-r--r-- 1 root root 3184 Dec 2 16:33 config
-rw-r--r-- 1 root root 1345 Dec 2 16:33 LICENSE
-rw-r--r-- 1 root root 54502 Dec 2 16:33 README.markdown
drwxr-xr-x 2 root root 4096 Dec 2 16:33 src
drwxr-xr-x 2 root root 4096 Dec 2 16:33 t
drwxr-xr-x 2 root root 52 Dec 2 16:33 util
-rw-r--r-- 1 root root 986 Dec 2 16:33 valgrind.suppress
重新编译安装 Nginx
- 查看 nginx 之前的编译参数:
[root@node106 ~]# nginx -V
nginx version: nginx/1.18.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --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-pcre --with-stream --with-stream_ssl_module --with-stream_realip_module
[root@node106 ~]#
- 添加 echo 模块,重新生成 Makefile:
[root@node106 ~]# cd /usr/local/src/nginx-1.18.0/
[root@node106 nginx-1.18.0]# ./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-pcre \
--with-stream \
--with-stream_ssl_module \
--with-stream_realip_module \
--add-module=/usr/local/src/echo-nginx-module
- 重新编译安装 nginx:
[root@node106 nginx-1.18.0]# make && make install
测试 echo 模块
- 编译配置文件:
server {
listen 192.168.1.106:80;
server_name www.yqc.com;
error_page 500 502 503 504 404 /error.html;
access_log /data/nginx/logs/www-yqc-com_access.log;
error_log /data/nginx/logs/www-yqc-com_error.log;
location / {
root /data/nginx/yqc/www;
index index.html;
}
location = /error.html {
root /data/nginx/yqc/redirect;
}
location = /status {
stub_status;
allow 192.168.1.0/24;
allow 127.0.0.1;
deny all;
}
location /main {
index index.html;
default_type text/html;
echo "hello world,main-->";
echo_reset_timer;
echo_location /sub1;
echo_location /sub2;
echo "took $echo_timer_elapsed sec for total.";
}
location /sub1 {
echo_sleep 1;
echo sub1;
}
location /sub2 {
echo_sleep 1;
echo sub2;
}
}
- 检查配置文件并重启nginx:
[root@node106 ~]# nginx -t
nginx: the configuration file /apps/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /apps/nginx/conf/nginx.conf test is successful
[root@node106 ~]# systemctl restart nginx
新装模块需要重启生效;
- 访问测试:
[root@node105 ~]# curl http://www.yqc.com/main
hello world,main-->
sub1
sub2
took 2.003 sec for total.