使用nginx和php实时产生缩略图

来源:互联网 发布:go语言与java 编辑:程序博客网 时间:2024/06/06 14:21
#假设,服务器上面有一个文件:abc.jpg,通过http://filefs.domain.com/file/abc.jpg能够访问到原图。其#实一般的,我们在数据库里面也就保存了“/file/abc.jpg”这部分内容。#现在,我们要实现通过http://filefs.domain.com/file/abc.jpg.w320.jpg由服务器自动产生#abc.jpg.w320.jpg(w320,320px的宽度)这个缩略图。并返回图片数据。#要满足以下两个条件:#1.如果abc.jpg.w320.jpg存在,则不重新产生图片#2.如果不存在,则在同一次的请求中,返回图片数据,和保存图片文件到服务器。server {listen       80;server_name  filefs.domain.com;root /var/www/http/filefs.domain.com;location / {index  index.html index.htm;}location ~ \.(png|jpg|jpeg|gif)$ {#如果文件不存在,则rewrite到产生图片的脚本文件autoimg.phpif (!-f $request_filename) {rewrite ^/.*$ /autoimg.php;expires max;}#如果文件存在,则设置过期时间,关闭访问日志if ( -f $request_filename ) {expires max;access_log off;}}error_page   500 502 503 504  /50x.html;location = /50x.html {root   /usr/share/nginx/html;}location ~ autoimg.php$ {#安全性考虑,文件服务器,只这个脚本文件的范围提交给php处理fastcgi_pass   127.0.0.1:9000;fastcgi_index  index.php;fastcgi_param  SCRIPT_FILENAME  /var/www/http/filefs.domain.com$fastcgi_script_name;include        /usr/local/nginx/conf/fastcgi_params;}}

本文章来至源码世界  http://www.ymsky.net/views/51664.shtml
0 0