gallery2 and nginx with rewrite return file not found for file name with space (or + sign in url)

Posted by Vangel on Server Fault See other posts from Server Fault or by Vangel
Published on 2012-06-09T20:22:04Z Indexed on 2012/06/09 22:42 UTC
Read the original article Hit count: 435

Filed under:
|
|

I have setup nginx with gallery2 on an internal server. Everything works fine under apache2 which I checked first, it used to be on apache2

Problem is: gallery2 seems to generate url with + sign in it for file names/ images which had spaces in it so a file like "may report.jpg" becomes "may+report.jpg"

The URL rewrite works but gallery2 throws an error for file not found. THis does not happen under apache2.

Here is my nginx rewrite rule:

   location / {
        index  main.php index.html;
        default_type text/html;
        # If the file exists as a static file serve it
        # directly without running all
        # the other rewite tests on it
        if (-f $request_filename) {
                break;
        }
        }
        location /v/
        {
   #    if ($request_uri !~ /main.php)
    #           {
                rewrite ^/v/(.*)$ /main.php?g2_view=core.ShowItem&g2_path=$1
                last;
#                }
        }

        location /d/
        {
        if ($request_uri !~ /main.php)
        {
                rewrite ^/d/([0-9]+)-([0-9]+)/(.*)$ /main.php?g2_view=core.DownloadItem&g2_itemId=$1&g2_serialNumber=$2&g2_fileName=$3
                last;
        }
        }


  location ~ \.php$ {
            fastcgi_pass   127.0.0.1:8889;
            fastcgi_index  main.php;
            fastcgi_intercept_errors on; # to support 404s for PHP files not found
            fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include        fastcgi_params;
            fastcgi_param SERVER_NAME $host;
            fastcgi_read_timeout 300;
        }

the sit on its own works fine. only the images with spaces in file name do not display in album view and also when clicking the the image for full page view will throw this error

Error (ERROR_MISSING_OBJECT) : Parent 103759 path report+april+456.flv
in modules/core/classes/helpers/GalleryFileSystemEntityHelper_simple.class at line 98 (GalleryCoreApi::error)
in modules/core/classes/GalleryCoreApi.class at line 1853 (GalleryFileSystemEntityHelper_simple::fetchChildIdByPathComponent)
in modules/core/classes/helpers/GalleryFileSystemEntityHelper_simple.class at line 53 (GalleryCoreApi::fetchChildIdByPathComponent)
in modules/core/classes/GalleryCoreApi.class at line 1804 (GalleryFileSystemEntityHelper_simple::fetchItemIdByPath)
in modules/rewrite/classes/RewriteSimpleHelper.class at line 45 (GalleryCoreApi::fetchItemIdByPath)
in ??? at line 0 (RewriteSimpleHelper::loadItemIdFromPath)
in modules/rewrite/classes/RewriteUrlGenerator.class at line 103
in modules/rewrite/classes/parsers/modrewrite/ModRewriteUrlGenerator.class at line 37 (RewriteUrlGenerator::_onLoad)
in init.inc at line 147 (ModRewriteUrlGenerator::initNavigation)
in main.php at line 180
in main.php at line 94
in main.php at line 83
System Information
Gallery version  2.2.4
PHP version  5.3.6 fpm-fcgi
Webserver    nginx/0.8.55
Database     mysqli 5.0.95
Toolkits     ImageMagick, Thumbnail, Gd
Operating system     Linux CentOS-55-64-minimal 2.6.18-274.18.1.el5 #1 SMP Thu Feb 9 12:45:44 EST 2012 x86_64
Browser  Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.52 Safari/536.5

In the report above there is usable system information if that helps. I know the nginx is old but it comes as default in centos repo and I am not sure if upgrading will fix the problem or break something else

it seems gallery2 must map the + to space internally but why it's not doing so with nginx I can't tell.

EDIT: I just verified that if I change the '+' sign to %20 then gallery2 works. but gallery2 is generating URL as +. I found a (maybe) related problem here for IIS7 and Gallery2 http://forums.asp.net/t/1431951.aspx

EDIT2: Accessing the URL without rewrite and having the + sign works. Must be something to do with rewrite. Here is the relevant apache2 rule that might be of help

RewriteCond %{THE_REQUEST} /d/([0-9]+)-([0-9]+)/([^/?]+)(\?.|\ .)
    RewriteCond %{REQUEST_URI} !/main\.php$
    RewriteRule .   /main.php?g2_view=core.DownloadItem&g2_itemId=%1&g2_serialNumber=%2&g2_fileName=%3   [QSA,L]

RewriteCond %{THE_REQUEST} /v/([^?]+)(\?.|\ .)
    RewriteCond %{REQUEST_URI} !/main\.php$
    RewriteRule .   /main.php?g2_path=%1   [QSA,L]

© Server Fault or respective owner

Related posts about nginx

Related posts about rewriterule