前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >手动编译nginx且添加echo lua brotli模块支持

手动编译nginx且添加echo lua brotli模块支持

作者头像
小柒吃地瓜
发布2020-04-22 16:42:25
1K0
发布2020-04-22 16:42:25
举报
文章被收录于专栏:梦在深巷

关于

这几天在家出不去门,没事干就重新部署了更新了服务器的环境与架构.但是之前用的nginx-openresty功能太复杂了,我也用不上.

所以我又重新再编译一次nginx,添加我目前可以用的模块.进行轻量级替换现有的版本.

主要用的第三方模块有:echo-nginx-module,lua-nginx-module,ngx_brotli,ngx_devel_kit,libbrotli

相关依赖有:OpenSSL,Lua-JIT

编译步骤如下

  • 相关源文件在官方网站和开源网站都能下载到,我就不放连接了.
代码语言:javascript
复制
#编译依赖
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 国际许可协议进行许可。 您可以自由的转载和修改,但请务必注明文章来源和作者署名并说明文章非原创且不可用于商业目的。

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2020 年 02 月,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 关于
  • 编译步骤如下
  • 测试结果
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档