第三模块是对nginx 的功能扩展,第三方模块需要在编译安装Nginx 的时候使用参数--addmodule=PATH指定路径添加
[root@localhost nginx-1.26.2]# nginx -s stop
[root@localhost conf.d]# cd /usr/local/src
[root@localhost src]# yum install git -y
[root@localhost src]# git clone https://github.com/openresty/echo-nginx-module.git
[root@localhost ~]# cd /nginx-1.26.2/
[root@localhost nginx-1.26.2]# ./configure --prefix=/software/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@localhost nginx-1.26.2]# make && make install
[root@localhost nginx-1.26.2]# nginx -V
nginx version: nginx/1.26.2
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=/software/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@localhost nginx-1.26.2]# cd /software/nginx/conf/conf.d/
[root@localhost conf.d]# vi uhn.conf
server {
listen 80;
server_name www.uhn.cn;
error_page 500 502 503 504 /error.html;
location = /error.html {
root /data/nginx/html/uhn;
}
location / {
root /data/nginx/html/uhn;
try_files $uri $uri.html $uri/index.html =911;
# auth_basic "login password";
# auth_basic_user_file /software/nginx/conf/.htpasswd;
}
location /testecho {
default_type text/html;
echo "test echo module";
echo $remote_addr;
}
}
测试echo正常工作生效了