• Resolved varunchopra

    (@varunchopra)


    Hi,

    I’m using nginx as the web server on my site and webp images aren’t generated out of the box. Is there some sort of documentation to help get this working with nginx?

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Author rosell.dk

    (@roselldk)

    You should basically “translate” the apache rules to NGINX.
    The apache rules vary depending on the webp express configuration, and whether you have moved your plugin folder and/or moved your wp-content folder.
    Look in your .htaccess to see the rules generated for your site – which then needs to be translated.

    Here are some pointers for creating the NGINX rules:

    https://github.com/S1SYPHOS/kirby-webp#nginx
    https://github.com/uhop/grunt-tight-sprite/wiki/Recipe:-serve-WebP-with-nginx-conditionally

    WebP Express is using the “WebP On Demand” solution, which is documented here: https://github.com/rosell-dk/webp-convert/blob/master/docs/webp-on-demand/webp-on-demand.md

    Plugin Author rosell.dk

    (@roselldk)

    Try inserting these rules into your Nginx configuration file (nginx.conf):
    `
    if ($http_accept ~* “webp”){
    rewrite ^/(.*).(jpe?g|png)$ /wp-content/plugins/webp-express/wod/webp-on-demand.php?source=$document_root$request_uri&wp-content=wp-content&%1 break;
    }
    `

    Plugin Author rosell.dk

    (@roselldk)

    Closed because of inactivity. Feel free to reopen if relevant…

    Try inserting these rules into your Nginx configuration file (nginx.conf):

    
    if ($http_accept ~* “webp”){
    rewrite ^/(.*).(jpe?g|png)$ /wp-content/plugins/webp-express/wod/webp-on-demand.php?source=$document_root$request_uri&wp-content=wp-content&%1 break;
    }
    

    I have tried it on the Nginx server, but it doesn’t work. Is there a solution?

    it doesn’t work. Is there a solution? Error: nginx failed to start with new config

    I cant get it to work either.

    Im on a bedrock/nginx setup (it works no problem with bedrock/apache, so bedrock shouldnt be the problem).

    These rules seems logical:

    if ($http_accept ~* “webp”) {
    rewrite ^/(.*).(jpeg|jpg)$ /app/plugins/webp-express/wod/webp-on-demand.php?source=$document_root$request_uri&wp-content=app&%1 break;
    }

    • This reply was modified 6 years, 3 months ago by pixelcrook.
    Plugin Author rosell.dk

    (@roselldk)

    Plugin Author rosell.dk

    (@roselldk)

    The rules contained illegal character “
    Also, $request_uri contains the querystring, which leads to trouble when a querystring is passed.
    And also, %1 doesn’t seem to do anything in Nginx. I removed it. In the Apache rules, it was there to pass the original query string on. But it seems the querystring is available in $_GET without any trickery

    Use these rules with 0.8.0:

    
    if ($http_accept ~* "webp"){
      rewrite ^/(.*).(jpe?g|png)$ /wp-content/plugins/webp-express/wod/webp-on-demand.php?xsource=x$request_filename&wp-content=wp-content break;
    }
    

    Use these rules with 0.7.0:

    
    if ($http_accept ~* "webp"){
      rewrite ^/(.*).(jpe?g|png)$ /wp-content/plugins/webp-express/wod/webp-on-demand.php?source=$request_filename&wp-content=wp-content break;
    }
    
    • This reply was modified 6 years, 3 months ago by rosell.dk.
    • This reply was modified 6 years, 3 months ago by rosell.dk.

    So, I finally got it to work. Don’t know what went wrong the first time.
    I used the same config as you except i switched the standard directories to Bedrocks. like this:

    if ($http_accept ~* “webp”){
    rewrite ^/(.*).(jpe?g|png)$ /app/plugins/webp-express/wod/webp-on-demand.php?xsource=x$request_filename&wp-content=app break;
    }

    Wrote up on it in a quick blog post as well.

    Thank you so much for this plugin!

    Plugin Author rosell.dk

    (@roselldk)

    I have come up with some improved Nginx rules. These takes care of adding Vary header, redirecting directly to existing webps and there are also rules for routing requests for non-existing webps to the converter. It’s in the FAQ. Check it out!

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘nginx rewrite rules’ is closed to new replies.