首先了解一下 nginx-http-concat,他是一个淘宝的开源Nginx模块,是一个能把多个CSS和JS合并成一个请求的Nginx模块,对于Web性能优化非常有意义。
Github地址:https://github.com/alibaba/nginx-http-concat,
先看看淘宝用起来是什么样的,访问淘宝网主页,查看源代码可以看到类似的这样的style/script链接
复制代码 代码如下:
<link rel="stylesheet" href="//g.tbcdn.cn/">
<script src="/UploadFiles/2021-04-10/">
是不是很神奇,只需要一个请求,就可以把需要的CSS/JS文件通过合并的方式把他输出成一个文件(注意,虽然淘宝有min格式的文件,但是这里它仅仅是合并多个文件,而不会自动的对其压缩打包文件)
首先我们先从Git上下载安装它
复制代码 代码如下:
#下载
$ git clone git://github.com/alibaba/nginx-http-concat.git
#移动目录
$ mv nginx-http-concat /usr/local/src/nginx-http-concat
查看原始Nginx版本,这很重要,因为我们需要安装同一个版本来升级数据
复制代码 代码如下:
#查看版本号以及配置信息(目录/模块)
$ /usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.3.1
TLS SNI support disabled
configure arguments: --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module
根据查询的版本号下载对应版本的nginx,可以到官方下载指定版本:http://nginx.org/download/
我这里使用的是1.3.1
复制代码 代码如下:
$ wget nginx-1.3.1.tar.gz
$ tar zxvf nginx-1.3.1.tar.gz
$ cd nginx-1.3.1
#根据上面-V的信息 加入concat模块所在路径 (--add-module=/usr/local/src/nginx-http-concat) 进行编译
$ ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --add-module=/usr/local/src/nginx-http-concat
make之前备份配置文件,防止意外
复制代码 代码如下:
$ cp -r /usr/local/nginx/conf /root/nginxconf
#编译安装
$ make && make install
接下来就是配置你的静态服务器conf文件
复制代码 代码如下:
server {
listen 80;
server_name static.dexphp.loc;
index index.html index.htm;
root /mnt/siteroot/static.dexphp.com;
location /static/css/ {
concat on;
concat_max_files 20; //最大合并文件数量是20个
}
location /status {
stub_status on;
access_log off;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|js)$ {
expires off;
}
error_log /mnt/siteroot/wwwlogs/static.dexphp.loc.error.log;
access_log /mnt/siteroot/wwwlogs/static.dexphp.loc.access.log;
}
更新日志
- 魏新雨《为你祈祷+新歌精逊2CD[WAV]
- 影心、明萨拉你选哪个?国外美女COS《博德3》
- 澳洲女子骑车跌入“自杀树”丛 疼痛持续9个月崩溃
- 育碧公布2024“她创力”计划:为女性游戏人提供辅导
- 刘美君.2017-千色·30总选3CD【环球】【WAV+CUE】
- 群星.2022-星河长明电视原声带【乐有奇思】【FLAC分轨】
- 陈淑桦.1995-淑桦盛开Forever【滚石】【WAV+CUE】
- 《再来一张》评测:出师成败皆系“赌”
- 《银河汉堡店》测评:我是银河走菜王!
- 萧煌奇《没事的》[320K/MP3][96.22MB]
- 萧煌奇《没事的》[FLAC/分轨][263.38MB]
- 群星《音你而来 第6期》[320K/MP3][90.61MB]
- 交错战线爬塔攻略一览
- 战锤40K星际战士2全近战武器使用教学|近战武器连招表
- 交错战线暴力队配队阵容一览