rosell-dk / webp-express

Wordpress plugin for serving autogenerated WebP images instead of jpeg/png to browsers that supports WebP
GNU General Public License v3.0
225 stars 64 forks source link

Path is outside resolved document root #526

Closed Akilesso closed 1 year ago

Akilesso commented 2 years ago

When i try to convert images i get error: Path is outside resolved document root.

What could be the problem? Thanks!

davidwebca commented 2 years ago

I also get this nowadays with a roots/bedrock install.

LucasDemea commented 1 year ago

Same here with a bedrock install

lockemx commented 1 year ago

I may be giving info that is not applicable to most because I am on trellis 1.10.1 + bedrock with WP 6.1, but, if you have symlinks in place, that may be the problem. I have it working on my installs. There's an incompatibility with how realpath is used to check if the image is in the document root. This really may not be your situation because I had the plugin working at first with all live tests passing, but then I tried to use a symlink for the app/webp-express directory.

I tried to use trellis tasks to symlink app/webp-express (alongside app/uploads). (I was giving it group write permissions for www-data user to use as well). If you do the same, the document root will be in a dated folder inside releases directory and the webp-express folder will be in the shared directory, at least as far as realpath reveals to be the case. I could be wrong, but I think this is the issue.

The following code is only necessary to support the releases system for trellis. If you can't get the plugin working, and you didn't try to use symlinks, I am not sure where the issue lies. I am not sure if I configured things in ansible in the most official way either. I ended up just setting up copying of the app/webp-express folder from release to release. I included my config for nginx. The trellis parts should be compatible with Apache.

group_vars/production/main.yml vendor and upload path are needed so you can't leave them off the new list

project_copy_folders:
  - vendor
  - "{{ project_public_path }}/app/webp-express"
project_shared_children:
  - path: "{{ project_public_path }}/{{ project_upload_path }}"
    src: uploads
  - path: "{{ project_public_path }}/app/themes/.htaccess"
    src: themes-htaccess
    type: file

group_var/all/main.yml

nginx_wordpress_site_conf: nginx-includes/wordpress-site.conf.child

nginx-includes/wordpress-site.conf.child

{% extends 'roles/wordpress-setup/templates/wordpress-site.conf.j2' %}

  {% block location_php -%}
  {{ super() }}

  # WebP Express rules
  location ~* ^/?app/.*\.(png|jpe?g)$ {
    add_header Vary Accept;
    expires 365d;
    if ($http_accept !~* "webp"){
      break;
    }
    try_files
      /app/webp-express/webp-images/doc-root/$uri.webp
      $uri.webp
      /app/plugins/webp-express/wod/webp-on-demand.php?xsource=x$request_filename&wp-content=app
      ;
  }

  # Route requests for non-existing webps to the converter
  location ~* ^/?app/.*\.(png|jpe?g)\.webp$ {
      try_files
        $uri
        /app/plugins/webp-express/wod/webp-realizer.php?xdestination=x$request_filename&wp-content=app
        ;
  }
  {%- endblock %}

EDIT: I should also mention that you need to provision once for the nginx config. The rest of the stuff is just in place so nothing breaks on the next deploy. Also, I realized I was doing some stuff wrong based on this link with child templates, but I think I corrected it. I stopped looking into the first time around because I got confused by using the combine filter to append to lists that have some preexisting values you might not want to touch.

EDIT2: I was doing this in a staging environment. Now that I have the default caching with Fast CGI cache on in production, it requires a different approach.

undisconnected commented 1 year ago

Hey there, I have encountered a problem after migrating my website to a new server. In Webp Express config, I can't choose the value Document root for the destination structure parameter. This causes the images not to display because the path is not the right one. Is there a known reason why this parameter would be disabled and set by default to Image roots?

I'm using nginx both before and after migration.

Thanks for your help