nginx添加第三方模块

1.理念

nginx除了支持内置模块,还支持第三方模块,但是第三方模块需要重新编译进nginx。
(重新生成nginx二进制命令)

1.如你的nginx默认不支持https
2.给你的nginx添加echo模块,用于打印nginx的变量。

 

2.编译添加echo模块

echo-nginx-module 模块可以在Nginx中用来输出一些信息,可以用来实现简单接口或者排错。

由于网络问题,建议该模块可以手动下载,编译安装

# 1.模块网址 https://github.com/openresty/echo-nginx-module

yum -y install gcc-c++ 

yum -y install pcre pcre-devel
yum -y install zlib zlib-devel
yum -y install openssl openssl-devel  

# 3.准备好nginx编译环境
yum install pcre pcre-devel openssl openssl-devel  zlib zlib-devel gzip  gcc gcc-c++ make wget httpd-tools vim -y
groupadd www -g 666
useradd www -u 666 -g 666 -M -s /sbin/nologin
mkdir -p /yuchaoit/ ; cd /yuchaoit/
# 下载echo模块
yum install git -y
git clone https://github.com/openresty/echo-nginx-module.git

# 4.编译nginx
wget http://nginx.org/download/nginx-1.19.0.tar.gz
tar -zxf nginx-1.19.0.tar.gz
cd nginx-1.19.0

./configure \
--user=www \
--group=www \
--prefix=/opt/nginx-1-19-0 \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-pcre \
--add-module=/yuchaoit/echo-nginx-module

# 5.编译且安装
make && make install 

# 6.创建快捷方式
ln -s /opt/nginx-1-19-0/sbin/nginx /usr/sbin/

# 7.验证模块
nginx -V

 

3.创建新配置文件,验证echo模块

[root@web-9 /etc/nginx/conf.d]#cat echo.conf 

server {
    listen       11444;
    server_name  localhost;
    charset utf-8;
    location / {
       echo "yuchaoit.cn welcome you!";
       echo $uri;
       echo $document_uri;
       echo $remote_addr;
       echo $remote_port;
       echo $http_user_agent;
    }
}

 

4.客户端访问

[root@master-61 ~]#curl 10.0.0.9:11444/hello_chaoge
yuchaoit.cn welcome you!
/hello_chaoge
/hello_chaoge
10.0.0.61
42378
curl/7.29.0

 你如果用浏览器去访问,nginx默认不会解析这个echo打印的内容,会提供下载功能,让你查看这些字符串

posted @ 2023-06-13 13:51  Mrterrific  阅读(770)  评论(0编辑  收藏  举报