关于
这几天在家出不去门,没事干就重新部署了更新了服务器的环境与架构.但是之前用的nginx-openresty
功能太复杂了,我也用不上.
所以我又重新再编译一次nginx,添加我目前可以用的模块.进行轻量级替换现有的版本.
主要用的第三方模块有:echo-nginx-module
,lua-nginx-module
,ngx_brotli
,ngx_devel_kit
,libbrotli
相关依赖有:OpenSSL
,Lua-JIT
编译步骤如下
- 相关源文件在官方网站和开源网站都能下载到,我就不放连接了.
#编译依赖
yum groupinstall -y "Development Tools"
#安装OpenSSL
[root@web-service-1 www]# tar xvf openssl-OpenSSL_1_1_1d.tar.gz
[root@web-service-1 www]# mv openssl-OpenSSL_1_1_1d openssl-1_1_1d
[root@web-service-1 www]# mv openssl-1_1_1d/ /usr/local/
#安装LuaJIT
[root@web-service-1 www]# tar xvf LuaJIT-2.0.5.tar.gz
[root@web-service-1 www]# cd LuaJIT-2.0.5/
[root@web-service-1 www]# make install PREFIX=/usr/local/LuaJIT
[root@web-service-1 www]# vim /etc/profile
export LUAJIT_LIB=/usr/local/LuaJIT/lib
export LUAJIT_INC=/usr/local/LuaJIT/include/luajit-2.0
[root@web-service-1 www]# source /etc/profile
#编译libbrotli
[root@web-service-1 www]# git clone https://github.com/bagder/libbrotli.git
[root@web-service-1 libbrotli]# cd libbrotli
[root@web-service-1 libbrotli]# ./autogen.sh
[root@web-service-1 libbrotli]# ./configure
[root@web-service-1 libbrotli]# make -j2 && maka install
#clone repo
[root@web-service-1 www]# git clone https://github.com/openresty/echo-nginx-module.git
[root@web-service-1 www]# git clone https://github.com/google/ngx_brotli.git
[root@web-service-1 www]# git clone https://github.com/openresty/lua-nginx-module.git #建议使用之前的稳定版本
#编译nginx
[root@web-service-1 www]# tar xvf nginx-1.17.0.tar.gz
[root@web-service-1 www]# cd nginx-1.17.0/
#--BEGIN--
#编译动态模块
./configure --prefix=/etc/nginx --sbin-path=/sbin/nginx --user=www --group=www --with-openssl=/usr/local/openssl-1_1_1d
--modules-path=/etc/nginx/modules --conf-path=/etc/nginx --error-log-path=/www/log/error.log --http-log-path=/www/log/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-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --with-compat
--with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module
--with-http_ssl_module --with-http_v2_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_addition_module
--with-http_auth_request_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_stub_status_module
--with-http_sub_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module
--add-dynamic-module=../ngx_brotli/ --add-dynamic-module=../echo-nginx-module/ --add-dynamic-module=../ngx_devel_kit/
--add-dynamic-module=../lua-nginx-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,-rpath,$LUAJIT_LIB'
#--END--
#--BEGIN--
#编译模块
./configure --prefix=/etc/nginx --sbin-path=/sbin/nginx --user=www --group=www --with-openssl=/usr/local/openssl-1_1_1d
--modules-path=/etc/nginx/modules --conf-path=/etc/nginx --error-log-path=/www/log/error.log --http-log-path=/www/log/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-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --with-compat
--with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module
--with-http_ssl_module --with-http_v2_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_addition_module
--with-http_auth_request_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_stub_status_module
--with-http_sub_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module
--add-module=../ngx_brotli/ --add-module=../echo-nginx-module/ --add-module=../ngx_devel_kit/ --add-module=../lua-nginx-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,-rpath,$LUAJIT_LIB'
#--END--
[root@web-service-1 nginx-1.17.0]# make -j2 && make install
测试结果
代码语言:javascript复制#nginx -V
[root@web-service-1 nginx-1.17.0]# nginx -V
nginx version: nginx/1.17.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC)
built with OpenSSL 1.1.1d 10 Sep 2019
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --sbin-path=/sbin/nginx --user=www --group=www --with-openssl=/usr/local/openssl-1_1_1d
--modules-path=/etc/nginx/modules --conf-path=/etc/nginx --error-log-path=/www/log/error.log --http-log-path=/www/log/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-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --with-compat --with-file-aio
--with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_ssl_module --with-http_v2_module
--with-http_gunzip_module --with-http_gzip_static_module --with-http_addition_module --with-http_auth_request_module --with-http_realip_module
--with-http_secure_link_module --with-http_slice_module --with-http_stub_status_module --with-http_sub_module --with-stream
--with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --add-module=../ngx_brotli --add-module=../echo-nginx-module
--add-module=../ngx_devel_kit --add-module=../lua-nginx-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,-rpath,$LUAJIT_LIB
#ngx_echo_module
[root@web-service-1 www]# vim /etc/nginx/nginx.conf
location / {
default_type 'text/plain';
echo 'is nginx work';
}
[root@web-service-1 www]# curl 127.0.0.1
is nginx work
[root@web-service-1 www]# vim /etc/nginx/nginx.conf
#ngx_lua_module
location / {
default_type 'text/plain';
content_by_lua_block {
ngx.say("is lua echo <is nginx work>")
}
}
[root@web-service-1 nginx-1.17.0]# curl 127.0.0.1
is lua echo <is nginx work>
版权属于:龙之介大人
本文链接:https://cloud.tencent.com/developer/article/1618777
本站所有原创文章采用知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议进行许可。 您可以自由的转载和修改,但请务必注明文章来源和作者署名并说明文章非原创且不可用于商业目的。