lnmp为nginx增加nginx_http_concat模块

NOCO发布于 分类 Nginx

8天前 有1个用户阅读过

lamp增加mod_concat模块的文章前几天我分享过一篇,lamp安装mod_concat模块合并css/js,减少请求提高页面整体加载速度

这次重庆SEO的测试环境为centos已安装lnmp,需要增加nginx_http_concat模块,步骤如下:

安装后面需要用到的组件

# yum install openssl openssl-devel pcre-devel git –y
下载nginx-http-concat模块
#git clone git://github.com/alibaba/nginx-http-concat.git
移动目录 后面configure会用到路径
#mv nginx-http-concat /root/nginx-http-concat

查看原始Nginx版本

这很重要,因为我们需要安装同一个版本来升级数据,configure arguments后面的内容记录下来,因为太长而且不同环境有所区别,本文用XXX表示 后面升级要用到

# nginx -V
nginx version: nginx/1.8.0
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-11) (GCC)
built with OpenSSL 1.0.1e-fips 11 Feb 2013
TLS SNI support enabled
configure arguments: xxx

下载对应的nginx版本并增加模块配置安装升级

# wget http://nginx.org/download/nginx-1.8.0.tar.gz
# tar zxvf nginx-1.8.0.tar.gz && cd nginx-1.8.0
#./configure xxx --add-module=/root/nginx-http-concat

安装之前先备份重要文件 以防意外,然后安装

# cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak
# cp /usr/sbin/nginx /usr/sbin/nginx.bak
# make && make install

检查NGINX运行情况,显示类似这样就表示NGINX安装成功了

# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

接下来就是配置你的静态服务器conf文件启用nginx-http-concat模块即可,本例中的在/static/下js,css文件使用nginx-http-concat

server {
 location /static/ {
 # nginx_concat_module 主开关
 concat on;
 # 最大合并文件数
 # concat_max_files 10;
 # 只允许同类型文件合并
 # concat_unique on;
 # 允许合并的文件类型,多个以逗号分隔。如:application/x-javascript, text/css
 # concat_types text/html;
 }
}

如果nginx_concat_module报400错误,原因和解决办法如下:

出现由于Nginx在新版本中,使用了标准的 MIME-Type:application/javascript。而在nginx_concat_module模块目前版本的代码中,写的是 application/x-javascript 的类型。也就是模块认不到js文件了。。。
因此,我们最好在向nginx添加该模块之前,修改nginx_concat_module的源代码文件ngx_http_concat_module.c,将application/x-javascript更改为application/javascript,然后再编译安装即可!

-- The End --

本文标题: lnmp为nginx增加nginx_http_concat模块

本文地址: https://seonoco.com/blog/lnmp-nginx-nginx_http_concat

本文是否有所帮助?
点赞 0
感谢支持
0
多谢反馈
评论 0
打赏

支持微信/支付宝

评论

网友