linux nginx css,nginx配置合并js和css文件请求

问题

于是乎在网上一搜,大概了解实现方法,于是自己也配置一下:

系统环境:1

2CentOS release 6.2 (Final)

Linux version 2.6.32-220.el6.x86_64

nginx和http_concat模块安装:1

2

3

4

5

6

7

8

9cd /usr/local/src/

wget http://nginx.org/download/nginx-1.4.2.tar.gz

wget https://github.com/alibaba/nginx-http-concat/archive/master.zip -O nginx-http-concat-master.zip

unzip nginx-http-concat-master.zip

tar -xzvf nginx-1.4.2.tar.gz

cd nginx-1.4.2/

./configure --prefix=/usr/local/nginx-1.4.2 --with-http_stub_status_module --add-module=../nginx-http-concat-master

make

make install

1

2

3

4

5tar -xzvf pcre-8.37.tar.gz

cd pcre-8.37/

./configure

make

make install

检查nginx的配置文件:1/usr/local/nginx-1.4.2/sbin/nginx -t

指定配置文件启动nginx:1/usr/local/nginx-1.4.2/sbin/nginx -c /usr/local/nginx-1.4.2/conf/nginx.conf

如果出现错误: error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directory,

解决办法:1

2cd /lib64

ln -s libpcre.so.0.0.1 libpcre.so.1

重新执行启动命令,访问ok!

接下来修改配置文件:1vim /usr/local/nginx-1.4.2/conf/nginx.conf

修改配置如下:1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20server {

listen 8080

server_name localhost

root /var/www/html

#charset koi8-r

#access_log logs/host.access.log main

location / {

root /var/www/html

index index.html index.htm

}

location /static/{

concat on

concat_max_files 20

concat_unique off

}

...

}

然后重新启动nginx服务:1

2/usr/local/nginx-1.4.2/sbin/nginx -s stop

/usr/local/nginx-1.4.2/sbin/nginx -c /usr/local/nginx-1.4.2/conf/nginx.conf

当然也可以热启动:1/usr/local/nginx-1.4.2/sbin/nginx -s reload

制作测试文件,添加一个index.html页面,并添加两个js文件:1

2

3

4

5//默认加载写法

//一次加载多个文件的写法

浏览器打开页面,查看网络加载,文件加载成功,并且合并成了一个!

感谢您的阅读,有不足之处请在评论为我指出!

参考资料

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值