需求:生产有个接口是通过socket通信。nginx1.9开始支持tcp层的转发,通过stream实现的,而socket也是基于tcp通信。

实现方法:Centos7.2下yum直接安装的nginx,添加新模块支持tcp转发;重新编译Nginx并添加 --with-stream 参数。

实现过程:

1.  查看nginx版本模块

[root@pre ~]# nginx -V

2.  下载一个同版本可编译的Nginx

cd /opt
wget http://nginx.org/download/nginx-1.12.2.tar.gz
tar xf nginx-1.12.2.tar.gz && cd nginx-1.12.

3.  备份原Nginx文件

mv /usr/sbin/nginx /usr/sbin/nginx.bak
cp -r /etc/nginx{,.bak}

4.  重新编译Nginx

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

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

根据第1步查到已有的模块,加上本次需新增的模块: --with-stream

cd /opt/nginx-1.12.2

./configure --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 --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --pid-path=/run/nginx.pid --lock-path=/run/lock/subsys/nginx --user=nginx --group=nginx --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 --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic' --with-ld-opt='-Wl,-z,relro -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,-E' --with-stream

以上编译时,如出现缺少依赖,一般需要安装以下模块,安装完再次编译:

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
yum -y install pcre-devel
yum -y install openssl openssl-devel

5.  编译通过,继续验证 
继续输入:make  
make完成后不要继续输入“make install”,以免现在的nginx出现问题 
以上完成后,会在objs目录下生成一个nginx文件,先验证:

/opt/nginx-1.12.2/objs/nginx -t
/opt/nginx-1.12.2/objs/nginx -V

6.  替换Nginx文件并重启

cp /opt/nginx-1.12.2/objs/nginx /usr/sbin/
nginx -s reload

7.  检查

[root@pre ~]# nginx -V

添加模块成功!!!

yum安装下的nginx,如何添加模块,和添加第三方模块的更多相关文章

  1. Python学习手册之__main__ 模块,常用第三方模块和打包发布

    在上一篇文章中,我们介绍了 Python 的 元组拆包.三元运算符和对 Python 的 else 语句进行了深入讲解,现在我们介绍 Python 的 __main__ 模块.常用第三方模块和打包发布 ...

  2. yum安装 lnmp (linux+nginx+php7.1+mysql5.7)

    1.第一步先更新yum update 2.yum安装nginx安装nginx最新源:yum localinstall http://nginx.org/packages/centos/7/noarch ...

  3. centos6服务器YUM安装LNMP(LINUX+NGINX+MYSQL+PHP)

    之前都用的lamp,这次配置一个lnmp来看看,试试Nginx是不是好用 关闭SELINUXvi /etc/selinux/config#SELINUX=enforcing #注释掉#SELINUXT ...

  4. centos yum安装redis,nginx

    先安装源 yum install epel-release 之后 分别安装redis,nginx

  5. python_way ,day5 模块,模块3 ,双层装饰器,字符串格式化,生成器,递归,模块倒入,第三方模块倒入,序列化反序列化,日志处理

    python_way.day5 1.模块3 time,datetime, json,pickle 2.双层装饰器 3.字符串格式化 4.生成器 5.递归 6.模块倒入 7.第三方模块倒入 8.序列化反 ...

  6. ubuntu 下编译安装 mysql php nginx 及常见错误 (持续添加)

    mysql mysql 可以使用mysql 官方提供的apt源进行安装 参见这里 php 安装前先安装一些常见库 sudo apt-get install libpng16-16 libpng16-d ...

  7. centos7 yum 安装最新的nginx 1.16

    参考:https://www.cnblogs.com/opsprobe/p/10773582.html nginx官方文档说明:http://nginx.org/en/linux_packages.h ...

  8. 解决centos yum安装"No package nginx available."问题

    问题原因: nginx位于第三方的yum源里面,而不在centos官方yum源里面 解决方法: 安装epel(Extra Packages for Enterprise Linux) a.去epel网 ...

  9. yum 安装 PHP,apache,nginx,mysql

    如果是Centos OS 64 位,首先更新 rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarc ...

随机推荐

  1. Linux c 从文件当中读取任意一行的数据

    代码如下 #include <stdio.h>#include <stdlib.h>#include <sys/stat.h>#include <sys/ty ...

  2. SpringMVC 搭建遇到的坑

    1. Caused by: org.xml.sax.SAXParseException; lineNumber: 8; columnNumber: 60; cvc-complex-type.2.4.c ...

  3. 一个简易的allocator

    #include <vector> #include <iostream> #include <algorithm> using namespace::std; t ...

  4. 使用md5加密算法完成简单的登录和注册功能

    原理: 登录:后端controller层获取到客户的密码,通过下面代码:new Sha256Hash(pwd).toHex();将密码转换成md5散列,生成一个新的字符串与数据库的值进行比对,根据不同 ...

  5. JavaScript的使用你知道几种?(上)

    往期回顾 在上一期的<JavaScript的组成 | DOM/BOM>☜里,我们有对文档对象模型-DOM.浏览器对象模型-BOM 这两大部分进行了解学习,如果有还不是很明白的小伙伴们,可以 ...

  6. traceroute命令初探

    一.学习目标 了解traceroute基本概念 了解traceroute工作原理及详细过程 熟悉traceroute常用命令 一些注意点 二.traceroute基本概念 traceroute (Wi ...

  7. DisplayLink 安装错误

    根据 在官网论坛上的反馈结果,程序自己有验证数字签名,数字签名验证不通过,即如上图所示.可能的原因:病毒:下载不完全:证书链出问题

  8. JAVA学习笔记系列4-Eclipse版本选择

    下载Eclipse需要根据安装的JDK的版本来决定是安装32位还是64位,不是根据操作系统选的.

  9. centos7.3 64位 安装git

    1.安装编译git时需要的包 # yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel # yum ins ...

  10. C# 读写欧姆龙(Omron)PLC ,C#使用Fins-tcp协议读写数据

      本文将使用一个gitHub开源的组件技术来读写西门子plc数据,使用的是基于以太网的TCP/IP实现,不需要额外的组件,读取操作只要放到后台线程就不会卡死线程,本组件支持超级方便的高性能读写操作 ...