yum安装下的nginx,如何添加模块,和添加第三方模块

背景:centos7下yum直接安装的nginx,添加新模块

1、查看nginx版本模块
nginx -V
这里写图片描述

2、下载一个同版本的可编译的nginx
cd /home/ngadm
wget http://nginx.org/download/nginx-1.12.2.tar.gz
tar zxvf nginx-1.12.2.tar.gz && cd nginx-1.12.2

3、备份、备份、备份
备份文件
mv /usr/sbin/nginx /usr/sbin/nginx.20180720
cp -r /etc/nginx /etc/nginx.20180720

4、检查模块是否支持,比如这次添加 limit 限流模块 和 stream 模块:
./configure –help | grep limit
这里写图片描述
ps:-without-http_limit_conn_module disable 表示已有该模块,编译时,不需要添加

./configure –help | grep stream
这里写图片描述
ps:–with-stream enable 表示不支持,编译时要自己添加该模块

根据第二步查到已有的模块,加上本次需新增的模块,那么最终结果如下:

./configure –user=nginx –group=nginx –prefix=/usr/share/nginx –sbin-path=/usr/sbin/nginx –modules-path=/usr/lib64/nginx/modules –conf-path=/etc/nginx/nginx.conf –error-log-path=/var/log/nginx/error.log –http-log-path=/var/log/nginx/access.log –with-stream –with-file-aio –with-ipv6 –with-http_auth_request_module –with-http_ssl_module –with-http_v2_module –with-http_realip_module –with-http_addition_module –with-http_xslt_module=dynamic –with-http_image_filter_module=dynamic –with-http_geoip_module=dynamic –with-http_sub_module –with-http_dav_module –with-http_flv_module –with-http_mp4_module –with-http_gunzip_module –with-http_gzip_static_module –with-http_random_index_module –with-http_secure_link_module –with-http_degradation_module –with-http_slice_module –with-http_stub_status_module –with-http_perl_module=dynamic –with-mail=dynamic –with-mail_ssl_module –with-pcre –with-pcre-jit –with-stream=dynamic –with-stream_ssl_module –with-debug

以上编译时,如出现缺少依赖,一般需要安装以下模块,安装完再次编译:
yum -y install libxml2 libxml2-dev libxslt-devel
yum -y install gd-devel
yum -y install perl-devel perl-ExtUtils-Embed
yum -y install GeoIP GeoIP-devel GeoIP-data

5、编译通过,继续验证
继续输入:make -j2
禁止:千万不要继续输入“make install”,以免现在的nginx出现问题
以上完成后,会在objs目录下生成一个nginx文件,先验证:
objs/nginx -t
objs/nginx -V

6、文件替换,并重启
以上成功后:
cp objs/nginx /usr/sbin/
nginx -s reload

重启:
nginx -s stop && nginx

补充:添加第三方模块时,先下载需要的模块,例如:echo模块
cd /usr/local/src
wget https://github.com/openresty/echo-nginx-module/archive/v0.61.tar.gz
tar zxvf v0.61.tar.gz

然后在编译时,加上模块的路径:
./configure –user=nginx –group=nginx –prefix=/usr/share/nginx –sbin-path=/usr/sbin/nginx –modules-path=/usr/lib64/nginx/modules –conf-path=/etc/nginx/nginx.conf –error-log-path=/var/log/nginx/error.log –http-log-path=/var/log/nginx/access.log –with-stream –with-file-aio –with-ipv6 –with-http_auth_request_module –with-http_ssl_module –with-http_v2_module –with-http_realip_module –with-http_addition_module –with-http_xslt_module=dynamic –with-http_image_filter_module=dynamic –with-http_geoip_module=dynamic –with-http_sub_module –with-http_dav_module –with-http_flv_module –with-http_mp4_module –with-http_gunzip_module –with-http_gzip_static_module –with-http_random_index_module –with-http_secure_link_module –with-http_degradation_module –with-http_slice_module –with-http_stub_status_module –with-http_perl_module=dynamic –with-mail=dynamic –with-mail_ssl_module –with-pcre –with-pcre-jit –with-stream=dynamic –with-stream_ssl_module –with-debug –add-module=/usr/local/src/echo-nginx-module-0.61

后续的操作和 第5、6步一样

Nginx 中启用第三方 MQTT 模块通常涉及以下几个步骤,这里以使用官方推荐的 ngx_mqtt 模块为例: 1. **安装模块**: - 对于 RPM 包管理系统的 Linux 发行版(如 CentOS、RHEL),你可以从 EPEL仓库或模块官方网站下载并安装 ngx_mqtt。例如:`sudo yum install epel-release nginx-extras` 然后 `sudo yum install ngx_mqtt`. - 对于 Debian/Ubuntu 系统,先安装依赖包,然后使用 APT 安装:`sudo apt-get update && sudo apt-get install nginx-extras libssl-dev libxml2-dev pcre-dev`,接着安装 ngx_mqtt:`sudo apt-get install nginx-headers-more-module nginx-module-xslt`。 2. **编译模块**: - 编译时添加 `-I/path/to/nginx/include` `-L/path/to/nginx/modules` 到你的 CFLAGS LDFLAGS 里,其中 `/path/to/nginx` 是你的 Nginx 安装目录。 - 将 ngx_mqtt 源码解压并进入目录,然后运行 `./configure` 命令,带上上面提到的选项进行编译。 - 最后执行 `make` `make install` 以安装模块Nginx 的插件目录。 3. **加载模块**: - 打开 Nginx 的配置文件(通常是 `/etc/nginx/nginx.conf`),找到 `http` 或 `stream` 部分,在该部分添加以下内容来启用模块: ```nginx load_module /path/to/nginx/modules/ngx_mqtt.so; ``` - 确保替换 `path/to/nginx` 为你实际的模块安装路径。 4. **配置 MQTT 相关的 location**: 在 Nginx 配置中创建一个 `location` 配置来监听 MQTT 请求,就像之前提到的那样。 完成以上步骤后,重启 Nginx 使其应用新的配置,并开始代理 MQTT 流量。 **相关问题--:** 1. ngx_mqtt 模块与原生 Nginx 的 MQTT 功能相比有何优势? 2. 如何测试 Nginx 是否成功地代理了 MQTT 通信? 3. ngx_mqtt 模块如何处理客户端认证?
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值