FileField Nginx Progress模块让nginx也支持drupal的upload progress

1 post / 0 new
observer
observer's picture
FileField Nginx Progress模块让nginx也支持drupal的upload progress
FileField Nginx Progress实际上是扩展了FileField的Javascript上传进度条,使其在Nginx下也可以正常使用。 所以安装FileField Nginx Progress需要事先安装好FileField
下面内容来自: http://d7.drupals.cn/node/299

Drupal的Filefield模块原生支持pecl的uploadprogress扩展,但是pecl的uploadprocess只支持apache!

还好nginx也有个upload progress模块,有高手为此写了个对应的drupal模块:FileField Nginx Progress

可惜的是,该模块的配置文档只有寥寥几行字,而drupal官方仅支持apache,关于nginx的文档实在不多,而且权威性有限。我东拼西凑搞了份nginx的配置,用着都没有什么问题,就是upload progress出不了。

考虑到安全性,这里仅贴出一部分配置:       

# Clean URLs rewrite rule
if (!-e $request_filename) {
        rewrite  ^(.*)$  /index.php?q=$1  last;
}

#nginx uploadprogress
location ~ (.*)/x-progress-id:(\w*) {
     rewrite ^(.*)/x-progress-id:(\w*)   $1?X-Progress-ID=$2;
}

location ^~ /progress {
     report_uploads uploads;
}

首先查看nginx的error日志,说too large file,原来nginx默认只支持1m的上传大小,需要在http{}里加上

  client_max_body_size           48m;

这里指支持48m的上传文件大小限制。

再查nginx的access日志,/progress返回404,我估计是Clean URLs rewrite的规则出了问题,覆盖了location /progress的虚拟目录设置。于是我把rewrite rule去掉,可uploadgress依然出不来。

最后我打算放弃了,想着顺手把Clean URLs rewrite的规则修改一下,令其支持自定义的location,就算了。于是我在Clean urls rewrite的配置外面前加上location /,因为location /默认的匹配所有url,但其它正则表达式的location优先。这样Clean URLs rewrite规则就不会影响其它自定义location的设定了。

修改后配置如下:

       

# Clean URLs rewrite rule
location / {
    if (!-e $request_filename) {
         rewrite  ^(.*)$  /index.php?q=$1  last;
    }
}

#nginx uploadprogress
location ~ (.*)/x-progress-id:(\w*) {
    rewrite ^(.*)/x-progress-id:(\w*)   $1?X-Progress-ID=$2;
}

location ^~ /progress {
    report_uploads uploads;
}

修改完成后试了上传,竟发现upload progress的进度出来了,真是激动得眼泪水都快掉下来。原来就差个clean url!

 

© 2011 CMS中文社区.. Drupal theme by Kiwi Themes.