详细教程请看:http://homeway.me/2015/06/22/nginx-lua-static-merger/
nginx-lua-static-merger
是一个基于openresty的模块,主要用于合并静态文件,减少http请求,加快静态文件访问速度的模块。
使用nginx-lua-static-merger
需要在编译nginx时候添加openresty的模块,或者直接安装openresty作为服务器。
nginx-lua-static-merger
可以让你的js、css请求不要那么多,一个就够了。
wget http://openresty.org/download/ngx_openresty-1.7.10.1.tar.gz
tar xzvf ngx_openresty-1.7.10.1.tar.gz
cd ngx_openresty-1.7.10.1/
./configure
make
make install
$git clone https://github.com/grasses/nginx-lua-static-merger
$cd nginx-lua-static-merger
$chmod +x install
$./install
Remember install openresty before run install script.
|--/usr/local/openresty/nginx
| `--lua
| `--nginx-lua-static-merger.lua
| `--conf
| `--nginx.lua
|--/www/openresty/static
| `--js
| `--css
| `--cache
注意
1、nginx.conf
中的lua_package_path "/usr/local/openresty/lualib/?.lua;;";
和
lua_package_cpath "/usr/local/openresty/lualib/?.so;;";
,如果你是编译nginx而不是直接安装openresty,目录记得放对。
2、确保/www/openresty/static
有Lua写的权限。
前端调用方法如下:
<link rel="stylesheet" href="/bootstrap/css/bootstrap.min.css;/qiniu/css/main.css;/css/navbar.css">
<script src="/js/jquery.min.js;/js/main.js;/qiniu/bootstrap/js/bootstrap.min.js;/qiniu/js/plupload/plupload.full.min.js;/qiniu/js/plupload/i18n/zh_CN.js"></script>
Nginx在location通过 content_by_lua_file
把接下来的处理丢个Lua做逻辑。
Lua通过uri进行md5编码,判断cache是否存在,如果cache不存在,循环分割、遍历uri,访问响应的路径,查找静态文件,存在则记录,最后写cache入文件,方便下次访问。
15.06.22
15.06.26
Fix a bug (single static file error)
Add install script
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。