发布于 2016-02-12 01:34:50 | 171 次阅读 | 评论: 0 | 来源: 网友投递
Nginx WEB服务器
Nginx 是一个高性能的 HTTP 和 反向代理 服务器,也是一个 IMAP/POP3/SMTP 代理服务器。 Nginx 是由 Igor Sysoev 为俄罗斯访问量第二的 Rambler.ru 站点开发的,第一个公开版本0.1.0发布于2004年10月4日。其将源代码以类BSD许可证的形式发布,因它的稳定性、丰富的功能集、示例配置文件和低系统资源的消耗而闻名。
首先了解一下 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/??tb/global/2.1.6/global-min.css,tb/tb-fp/1.2.3/style-min.css?t=20130912">
<script src="//g.tbcdn.cn/??kissy/k/1.3.1/seed-min.js,tb/global/2.1.6/global-min.js,tb/tb-fp/1.2.3/core-min.js?t=20130912"></script>
首先我们先从Git上下载安装它
#下载
$ git clone git://github.com/alibaba/nginx-http-concat.git
#移动目录
$ mv nginx-http-concat /usr/local/src/nginx-http-concat
#查看版本号以及配置信息(目录/模块)
$ /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
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;
}