对于一些门户网站来说,经常需要在不同的场合使用不同的缩略图。如果预先不知道需要生成的缩略图的尺寸情况下,我们可以先使用nginx进行url判断,如果图片不存在则把请求转发到php脚本进行缩略图生成处理,然后显示出来。
本文需要完全的任务如下,
- 根据请求生成固定宽高的缩略图,并存储到又拍服务器
- 根据请求生成固定宽度的缩略图,并存储到又拍服务器
- 图像生成一次之后,以后可直接调用
server
{
listen 80;
server_name www. example. com;
index index. php;
root /home /wwwroot /www. example. com;
include other. conf;
location ~ /. svn {
deny all;
}
location ~ . *\. (php |php5 )?$ {
try_files $uri = 404;
fastcgi_pass unix: /tmp /php -cgi. sock;
fastcgi_index index. php;
include fcgi. conf;
}
location / {
if (! -e $request_filename ) {
rewrite ^ (. * )$ /index. php?s=$1 last;
}
}
location ~ . *\. (gif |jpg |jpeg |png |bmp |swf |ico )$ {
location ~ * /resize / (. + )$ {
proxy_pass http: //www. example. com /?m=Api &a=resize &s=$1 &args;
break;
}
expires max;
}
location ~ . *\. (js |css )?$ {
expires 30d;
}
}
listen 80;
server_name www. example. com;
index index. php;
root /home /wwwroot /www. example. com;
include other. conf;
location ~ /. svn {
deny all;
}
location ~ . *\. (php |php5 )?$ {
try_files $uri = 404;
fastcgi_pass unix: /tmp /php -cgi. sock;
fastcgi_index index. php;
include fcgi. conf;
}
location / {
if (! -e $request_filename ) {
rewrite ^ (. * )$ /index. php?s=$1 last;
}
}
location ~ . *\. (gif |jpg |jpeg |png |bmp |swf |ico )$ {
location ~ * /resize / (. + )$ {
proxy_pass http: //www. example. com /?m=Api &a=resize &s=$1 &args;
break;
}
expires max;
}
location ~ . *\. (js |css )?$ {
expires 30d;
}
}