yum安装的Nginx添加模块支持tcp

Posted wemux

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了yum安装的Nginx添加模块支持tcp相关的知识,希望对你有一定的参考价值。

查看nginx版本及模块

[root@proxy ~]# nginx -V
nginx version: nginx/1.21.0
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=/etc/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 --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt=-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC --with-ld-opt=-Wl,-z,relro -Wl,-z,now -pie

下载同版本可编译Nginx

wget http://nginx.org/download/nginx-1.21.0.tar.gz
tar -zxvf nginx-1.21.0.tar.gz

备份原文件

mkdir nginx-backup
mv /usr/sbin/nginx nginx-backup/nginx.bak
cp -r /etc/nginx nginx-backup/

安装依赖包

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 gperftools
yum -y install gcc gcc-c++ make redhat-rpm-config

重新编译安装nginx

#根据nginx -V查到已有模块,新增--with-stream --with-stream_ssl_preread_module

cd nginx-1.21.0
./configure \\
--prefix=/etc/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 \\
--pid-path=/var/run/nginx.pid \\
--lock-path=/var/run/nginx.lock \\
--http-client-body-temp-path=/var/cache/nginx/client_temp \\
--http-proxy-temp-path=/var/cache/nginx/proxy_temp \\
--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \\
--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \\
--http-scgi-temp-path=/var/cache/nginx/scgi_temp \\
--user=nginx \\
--group=nginx \\
--with-compat \\
--with-file-aio \\
--with-threads \\
--with-http_addition_module \\
--with-http_auth_request_module \\
--with-http_dav_module \\
--with-http_flv_module \\
--with-http_gunzip_module \\
--with-http_gzip_static_module \\
--with-http_mp4_module \\
--with-http_random_index_module \\
--with-http_realip_module \\
--with-http_secure_link_module \\
--with-http_slice_module \\
--with-http_ssl_module \\
--with-http_stub_status_module \\
--with-http_sub_module \\
--with-http_v2_module \\
--with-mail \\
--with-mail_ssl_module \\
--with-stream --with-stream_realip_module \\
--with-stream_ssl_module \\
--with-stream_ssl_preread_module \\
--with-cc-opt=-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC \\
--with-ld-opt=-Wl,-z,relro -Wl,-z,now -pie \\
--with-stream \\
--with-stream_ssl_preread_module

编译通过以后,执行make, make完成后不要继续输入make install,验证

[root@proxy nginx-1.21.0]# ./objs/nginx -V
nginx version: nginx/1.21.0
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=/etc/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 --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt=-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC --with-ld-opt=-Wl,-z,relro -Wl,-z,now -pie --with-stream --with-stream_ssl_preread_module

替换nginx文件并重启

[root@proxy nginx-1.21.0]# cp ./objs/nginx /usr/sbin/
[root@proxy nginx-1.21.0]# systemctl start nginx

检查

[root@proxy nginx-1.21.0]# nginx -V
nginx version: nginx/1.21.0
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=/etc/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 --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt=-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC --with-ld-opt=-Wl,-z,relro -Wl,-z,now -pie --with-stream --with-stream_ssl_preread_module

以上是关于yum安装的Nginx添加模块支持tcp的主要内容,如果未能解决你的问题,请参考以下文章

使用Nginx实现UDP反向代理

nginx 安装并支持upstream监控

centos 使用yum安装nginx后如何添加模块?

CentOS 7 yum 安装 Nginx 以及 TCP流转发

原已经安装好的nginx,现在需要添加一个未被编译安装的模块:

nginx安装并支持upstream和tcp代理模块