第三方模块是对nginx 的功能扩展,第三方模块需要在编译安装Nginx 的时候使用参数–add-module=PATH指定路径添加,nginx支持第三方模块,需要从源码重新编译支持
[root@U8: ~]# /apps/nginx/sbin/nginx -s stop
[root@U8: ~]# vim /apps/nginx/conf/conf.d/pc.conf
server {
listen 80;
server_name dushansao.com;
location /main {
index index.html;
default_type text/html;
echo "Hello,this is dushansao.";
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@U8: ~]# /apps/nginx/sbin/nginx -t
nginx: [emerg] unknown directive “echo” in /apps/nginx/conf/conf.d/pc.conf:7
nginx: configuration file /apps/nginx/conf/nginx.conf test failed
#修复报错
[root@U8: ~]# nginx -V
nginx version: nginx/1.16.1
built by gcc 7.4.0 (Ubuntu 7.4.0-1ubuntu1~18.04.1)
built with OpenSSL 1.1.1 11 Sep 2018
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@U8: ~]# cd /usr/local/src/
[root@U8: /usr/local/src]# git clone https://github.com/openresty/echo-nginx-module.git
Cloning into 'echo-nginx-module'...
remote: Enumerating objects: 18, done.
remote: Counting objects: 100% (18/18), done.
remote: Compressing objects: 100% (13/13), done.
remote: Total 3015 (delta 8), reused 11 (delta 5), pack-reused 2997
Receiving objects: 100% (3015/3015), 1.15 MiB | 110.00 KiB/s, done.
Resolving deltas: 100% (1619/1619), done.
[root@U8: /usr/local/src]# ll
total 1020K
drwxr-xr-x 6 root root 4.0K Jan 8 20:35 echo-nginx-module/
drwxr-xr-x 9 1001 1001 4.0K Dec 30 20:33 nginx-1.16.1/
-rw-r–r-- 1 root root 1009K Dec 30 18:49 nginx-1.16.1.tar.gz
[root@U8: /usr/local/src]# cd nginx-1.16.1/
#重新编译安装nginx
[root@U8: /usr/local/src/nginx-1.16.1]# ./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
[root@U8: /usr/local/src/nginx-1.16.1]# make -j 4 && make install
#检查重启nginx服务
[root@U8: /usr/local/src/nginx-1.16.1]# /apps/nginx/sbin/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
#这里又出现pid报错
[root@U8: /usr/local/src/nginx-1.16.1]# /apps/nginx/sbin/nginx -s reload
nginx: [error] invalid PID number “” in “/apps/nginx/logs/nginx.pid”
#修复报错
[root@U8: /usr/local/src/nginx-1.16.1]# /apps/nginx/sbin/nginx -c /apps/nginx/conf/nginx.conf
#再次重启nginx服务
[root@U8: /usr/local/src/nginx-1.16.1]# /apps/nginx/