nginx重编译增加模块

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了nginx重编译增加模块相关的知识,希望对你有一定的参考价值。

cd ~/root/nginx

先下载模块源码包:

wget -O jemalloc-5.0.1.tar.bz2 http://125.88.182.172:5880/src/jemalloc-5.0.1.tar.bz2

wget -O pcre-$pcre_version.tar.gz http://125.88.182.172:5880/src/pcre-$pcre_version.tar.gz -T 5

wget -O /root/nginx/nginx-$nginxVersion.tar.gz http://125.88.182.172:5880/src/nginx-$nginxVersion.tar.gz -T20

wget -O openssl.tar.gz http://125.88.182.172:5880/src/openssl-1.0.2l.tar.gz -T 5

wget -O ngx_cache_purge.tar.gz http://125.88.182.172:5880/src/ngx_cache_purge-2.3.tar.gz

wget -O /root/nginx/conf/nginx.conf http://125.88.182.172:5880/conf/nginx.conf -T20

wget -O /root/nginx/html/index.html http://125.88.182.172:5880/error/index.html -T 5

wget -O nginx.init http://125.88.182.172:5880/init/nginx.init -T 5

wget -O waf.zip http://125.88.182.172:5880/install/waf/waf.zip

wget -c -O lua-5.3.4.tar.gz http://125.88.182.172:5880/install/src/lua-5.3.4.tar.gz -T 5

wget -c -O LuaJIT-2.0.4.tar.gz http://125.88.182.172:5880/install/src/LuaJIT-2.0.4.tar.gz -T 5

wget -c -O lua-nginx-module-master.zip http://125.88.182.172:5880/install/src/lua-nginx-module-master.zip -T 5

wget -c -O ngx_devel_kit-master.zip http://125.88.182.172:5880/install/src/ngx_devel_kit-master.zip -T 5

wget -c -O lua-nginx-module-master.zip http://125.88.182.172:5880/install/src/lua-nginx-module-master.zip -T 5

wget -c -O ngx_devel_kit-master.zip http://125.88.182.172:5880/install/src/ngx_devel_kit-master.zip -T 5

解压,需要编译的就编译,不需要的就不编译

tar -xvf jemalloc-5.0.1.tar.bz2

cd jemalloc-5.0.1

./configure

make && make install

ldconfig

cd ..

tar xzf pcre-8.40.tar.gz

yum install libtermcap-devel ncurses-devel libevent-devel readline-devel -y

tar xvf lua-5.3.4.tar.gz

cd lua-5.3.4

make linux

make install

cd ..

tar xvf LuaJIT-2.0.4.tar.gz

cd LuaJIT-2.0.4

make linux

make install

cd ..

export LUAJIT_LIB=/usr/local/lib

export LUAJIT_INC=/usr/local/include/luajit-2.0/

ln -sf /usr/local/lib/libluajit-5.1.so.2 /usr/local/lib64/libluajit-5.1.so.2

echo "/usr/local/lib" >> /etc/ld.so.conf

ldconfig  #

下面接着编译nginx

cd  nginx-1.12.2

./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --sbin-path=/usr/sbin/nginx --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=/tmp/nginx/client_body --http-proxy-temp-path=/var/nginx/proxy_temp_dir --http-fastcgi-temp-path=/tmp/nginx/fastcgi --pid-path=/var/run/nginx.pid --lock-path=/var/lock/subsys/nginx --add-module=/root/lnmp/ngx_devel_kit-master --add-module=/root/lnmp/lua-nginx-module-master --with-openssl=/root/lnmp/openssl-1.0.2l --with-http_v2_module --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-pcre=/root/lnmp/pcre-8.40 --with-http_realip_module --add-module=/root/lnmp/ngx_cache_purge-2.3 --with-http_gunzip_module --with-stream --with-stream_ssl_module --with-http_sub_module --with-http_flv_module --with-http_addition_module --with-http_mp4_module --with-ld-opt="-Wl,-E" --with-ld-opt="-ljemalloc"

只是增加模块:

make

[[email protected] nginx-1.12.2]# cp -ar objs/nginx /usr/sbin/nginx

cp: overwrite ‘/usr/sbin/nginx’? y

cp: cannot create regular file ‘/usr/sbin/nginx’: Text file busy

[[email protected] nginx-1.12.2]# cp /usr/sbin/nginx /usr/sbin/nginxbak

[[email protected] nginx-1.12.2]# service nginx stop

Stopping nginx (via systemctl): [ OK ]

[[email protected] nginx-1.12.2]# cp -ar objs/nginx /usr/sbin/nginx

cp: overwrite ‘/usr/sbin/nginx’? y

[[email protected] nginx-1.12.2]# service nginx start

Starting nginx (via systemctl): [ OK ]
如果全新安装:

make && make install

使用里面的配置文件去替换默认配置文件即可。

以上是关于nginx重编译增加模块的主要内容,如果未能解决你的问题,请参考以下文章

nginx编译增加模块

nginx 1.16.0编译安装及增加模块

想为线上环境Nginx增加一个模块,线上的nginx是通过rpm方式安装的(非编译安装),可以添加么?

NGINX动态增加模块,平滑升级

如何有条件地将 C 代码片段编译到我的 Perl 模块?

使用tengine DSO 来动态编译安装第三方模块(Lua