Nginx环境下wecenter优化减少http请求次数

Hanrak
Hanrak 这家伙很懒,还没有设置简介

0 人点赞了该文章 · 6316 浏览

具体思路 使用nginx-http-concat自动合并静态资源,加速网站请求速度 首先了解一下 nginx-http-concat,他是一个淘宝的开源Nginx模块,是一个能把多个CSS和JS合并成一个请求的Nginx模块,对于Web性能优化非常有意义。 Github地址:https://github.com/alibaba/nginx-http-concat 实战记录: ##一.为nginx添加nginx-http-concat模块 添加nginx-http-concat模块需要重新编译nginx 我是安装到了/home/n/ {{{ cd /home/n/ #下载模块源码 sudo wget https://github.com/alibaba/nginx-http-concat/archive/master.zip -O nginx-http-concat-master.zip #解压模块 sudo unzip nginx-http-concat-master.zip #下载nginx源码 sudo wget http://nginx.org/download/nginx-1.6.2.tar.gz #解压nginx sudo tar xzvf nginx-1.6.2.tar.gz cd nginx-1.6.2 ##查看本机nginx的信息 我的是VPS 终端输入(V要大写) nginx -V 得到配置信息 --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/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-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-http_auth_request_module --with-mail --with-mail_ssl_module --with-file-aio --with-ipv6 --with-http_spdy_module --with-cc-opt='-O2 -g -pipe -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic' ##开始添加模块 安装依赖库 我没装报错了 yum -y install openssl openssl-devel pcre-devel ./configure --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/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-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-http_auth_request_module --with-mail --with-mail_ssl_module --with-file-aio --with-ipv6 --with-http_spdy_module --with-cc-opt='-O2 -g -pipe -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic' --add-module=../nginx-http-concat-master sudo make 检查模块 objs/nginx -V 模块添加成功 更新nginx 先备份下原来的 sudo cp /usr/sbin/nginx /usr/sbin/nginx.bak 停止nginx(我的是测试小站 如果访问量大的可以平滑升级 具体百度) sudo systemctl stop nginx.service 复制新的过去 sudo cp objs/nginx /usr/sbin/nginx 启动nginx sudo systemctl start nginx.service 检测模块 nginx -V 替换成功 ##配置concat模块 sudo nano /etc/nginx/conf.d/default.conf server里加入 location /static/ { concat on; concat_types text/css; } location /static/js/ { concat on; concat_types application/javascript; } 重启 sudo systemctl restart nginx.service 到这里服务器就配置好了 ##下一步让wecenter用上nginx-http-concat模块 ##修改system/aws_controller.inc.php 85行改成 // 引入系统css 文件 TPL::import_css(array( '??css/default/common.css,css/default/link.css,js/plug_module/style.css', )); 97行改成 TPL::import_js(array( 'js/??jquery.js,respond.js', )); 106行改成 // 引入系统 JS 文件 TPL::import_js(array( 'js/??jquery.form.js,plug_module/plug-in_module.js,aws.js,aw_template.js,app.js', )); ##修改global/header_meta.tpl.htm 14行改成 <link rel="stylesheet" type="text/css" href="<?php echo G_STATIC_URL; ?>/css/??bootstrap.css,icon.css" /> 好了 现在修改完毕 测试OK }}}

发布于 2014-12-22 14:05

免责声明:

本文由 Hanrak 原创发布于 WeCenter ,著作权归作者所有。

登录一下,更多精彩内容等你发现,贡献精彩回答,参与评论互动

登录! 还没有账号?去注册

吴结草
2014-12-22 15:07
直接安装个 ngx_pagespeed 什么都帮你搞定了.
Hanrak
2014-12-22 16:19
不早点说 我先试试哈 ....................不知道兼容wc不
Hanrak
2014-12-22 16:54
部署了下ngx_pagespeed =真心不错 谢谢推荐
hydeist
2014-12-22 18:23
ngx_pagespeed是服务器插件吧?