`
yangwei0915
  • 浏览: 460734 次
  • 性别: Icon_minigender_1
  • 来自: 西安
社区版块
存档分类
最新评论

编译安装nginx并添加图片resize功能

 
阅读更多

一、安装nginx时必须先安装相应的编译工具

yum -y install gcc gcc-c++ autoconf automake

yum -y install zlib zlib-devel openssl openssl-devel pcre-devel

 

 

zlib:nginx提供gzip模块,需要zlib库支持

openssl:nginx提供ssl功能

pcre:支持地址重写rewrite功能

 

二、执行解压命令解压 tar -zxvf nginx-1.6.2.tar.gz

 

三、编译和安装

 

cd nginx-1.6.2

 

------编译安装配置

#  ./configure --prefix=/usr/local/nginx-1.6.2 --with-http_image_filter_module

------编译和安装

#  make && make install

 

四、修改配置

在/usr/local/nginx-1.6.2/conf目录下的nginx.conf文件中的设置为文件服务器的server节点,增加如下内容:

location ~* ^/img/w_(\d+)/h_(\d+)/(.*)$ {  

               proxy_pass  http://127.0.0.1/img/$3?width=$1&height=$2;  

               proxy_set_header Host  $host;  

               proxy_set_header X-Real-IP  $remote_addr;  

               proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;  

               #proxy_cache cache_one;  

               proxy_cache_valid  200 304 12h;  

               proxy_cache_key $host$uri$is_args$args;  

               add_header X-Cache "ImageCache Status: $upstream_cache_status";  

}     

location /img/{  

                alias /usr/local/nginx-1.6.2/html/img/;  

                image_filter resize $arg_width $arg_height;  

                image_filter_buffer 50M;

}

 

注:

/usr/local/nginx-1.6.2/html/img/ 为图片在linux上存放的位置

mage_filter_buffer 50M;  为最大图片缓冲大小

 

 

------启动

执行命令进行启动 /usr/local/nginx-1.6.2/sbin/nginx

 

访问:

原图

http://hostname/img/image4.jpg

压缩图:

http://hostname/img/resize/w_120/h_129/image4.jpg

 

 

 

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics