Nginx的性能让人欲罢不能,结合最近安装nginx和部分模块的经验,这里总结下。
目前糅合的模块功能有:
- nginx 1.15.0(当前最新版)
- nginx-http-concat 1.2.2 (Alibaba开发的合并请求模块)
- nginx_http_trim_filter (淘宝tengine的html、css、js压缩模块)
- OpenSSL_1_1_1-pre2(可以开始TLS 1.3 版本是Draft 23,最新的Chrome浏览器支持23)
- lua-nginx-module-0.10.13(在nginx中嵌入Lua,使用lua脚本逻辑完成部分轻业务)
- ngx_devel_kit-0.3.1rc1(Nginx开发库,嵌入lua需要)
- LuaJIT-2.1.0-beta3(Lua的编译器,嵌入lua需要)
整体安装过程如下(下面操作均在/opt/nginx_source目录下进行,按需修改):
#apt install libpcre3-dev #apt install libssl-dev wget http://aliyun.beecdn.cn/linuxpack/nginx/LuaJIT-2.1.0-beta3.tar.gz wget http://aliyun.beecdn.cn/linuxpack/nginx/lua-nginx-module_v0.10.13.tar.gz wget http://aliyun.beecdn.cn/linuxpack/nginx/nginx_http_trim_filter_cn.zip wget http://aliyun.beecdn.cn/linuxpack/nginx/nginx-1.15.0.tar.gz wget http://aliyun.beecdn.cn/linuxpack/nginx/nginx-http-concat-1.2.2.zip wget http://aliyun.beecdn.cn/linuxpack/nginx/ngx_devel_kit_v0.3.1rc1.tar.gz wget http://aliyun.beecdn.cn/linuxpack/nginx/OpenSSL_1_1_1-pre2.zip tar -zxvf LuaJIT-2.1.0-beta3.tar.gz tar -zxvf lua-nginx-module_v0.10.13.tar.gz tar -zxvf nginx-1.15.0.tar.gz tar -zxvf ngx_devel_kit_v0.3.1rc1.tar.gz unzip nginx_http_trim_filter_cn.zip unzip nginx-http-concat-1.2.2.zip unzip OpenSSL_1_1_1-pre2.zip cd /opt/nginx_source/LuaJIT-2.1.0-beta3 make make install PREFIX=/opt/programs/luaJIT ln -sf luajit-2.1.0-beta3 /opt/programs/luaJIT/bin/luajit cd /opt/nginx_source/nginx-1.15.0 export LUAJIT_LIB=/opt/programs/luaJIT/lib export LUAJIT_INC=/opt/programs/luaJIT/include/luajit-2.1 ./configure --prefix=/opt/programs/nginxwithlua --with-openssl=/opt/nginx_source/OpenSSL_1_1_1-pre2 --with-openssl-opt='enable-tls1_3 enable-ec_nistp_64_gcc_128 enable-weak-ssl-ciphers' --with-http_v2_module --with-http_ssl_module --with-http_stub_status_module --with-http_gzip_static_module --with-ld-opt="-Wl,-rpath,/opt/programs/luaJIT/lib" --add-module=/opt/nginx_source/nginx-http-concat-1.2.2 --add-module=/opt/nginx_source/nginx_http_trim_filter_cn --add-module=/opt/nginx_source/lua-nginx-module-0.10.13 --add-module=/opt/nginx_source/ngx_devel_kit-0.3.1rc1 make make install
安装完成后,可以引入下openresty的lua库,打包下载:https://aliyun.beecdn.cn/linuxpack/nginx/lualib.zip
解压后放在Nginx安装目录下。测试下lua功能,编辑nginx配置文件:
#在http段下,定义lua模块的位置 lua_package_path '/opt/programs/nginxwithlua/lualib/?.lua'; #定义c模块的位置 lua_package_cpath '/opt/programs/nginxwithlua/lualib/?.so'; #各个server端配置 server{ location /test{ content_by_lua_block { ngx.say("Hello world") } } }