Support » Plugin: WebP Express » nginx rewrite rules
nginx rewrite rules
-
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?
-
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-conditionallyWebP 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
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;
}
`
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 12 months ago by
pixelcrook.
Latest info available in this thread:
https://wordpress.org/support/topic/tests-succeed-but-php-errors-abound-and-site-images-not-converting/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 trickeryUse 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; }
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!
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!
-
This reply was modified 12 months ago by
- The topic ‘nginx rewrite rules’ is closed to new replies.