Skip to content

NGINX WebPRealizer Sanity Check Failed with symlink for upload repository #614

@asimongm

Description

@asimongm

Hello !

I have an issue on SanityCheck::absPathIsInDocRoot() function, because I use a symlink on my repository.

I see that there is already a fix (#429), but it's not working on my case.

I use automatic deployment, and for this I have releases folders.
My realpath is : /var/www/site.com/public_html/releases/19 but I use a symlink as directory root : /var/www/site.com/public_html/current/ (that is using files in this directory : /var/www/site.com/public_html/releases/19).

Here is what I noticed :

Apache

  • If I use Apache, I can choose "Image Roots" for "Destination structure" parameter, so when It call the "getDestination" function, It use "getDestinationNoDocRoot()" function, and it's working.

NGINX

  • If I use NGINX, it's always using getDestinationDocRoot() function in WebPRealizer(), so it check Sanity, but here is my problem, in the absPathIsInDocRoot() function of SanityCheck, $input return this : "/var/www/site.com/public_html/current/web/app/uploads/2024/11/filename.webp" but the realpath is "/var/www/site.com/public_html/releases/19/" so the Sanity Check fail because this code return false :
strpos($input, $docRootSymLinksExpanded . '/') 

because $docRootSymLinksExpanded return "/var/www/site.com/public_html/releases/19/".

Could you try to fix this use case ? Because I can't generate webp image on demand when I load inexistant webp files.

I test to add this code in SanityCheck.php file, on line 315, it's working with this trick, but I'm not sure it's really the best way, so I'm trying to ask help, if you can find a better way, or if it's okay, to add this in next release of the plugin.

// See if $filePath begins with the realpath of the $docRoot + '/'. If it does, we are done and OK!
// (pull #429)
if (strpos($input, $docRootSymLinksExpanded . '/') === 0 || strpos($input, $docRoot . '/') === 0) {
  return $input;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions