+1 vote
by Rookie

I'm trying to implement WebP on my WordPress installation. WebP images are generated using ShortPixel and I'm following their documentation to configure serving of WebP through Nginx. https://shortpixel.helpscoutdocs.com/article/111-configure-nginx-to-transparently-serve-webp-files-when-supported.

Basically what I did is, in /etc/nginx/sites-available/site.com at the start I added

map $http_accept $webp_suffix {

        default "";

        "~*webp" ".webp";


and in /var/www/site.com/*-nginx.conf  I added this piece of code.

location ~* ^(/wp-content/.+)\.(png|jpe?g)$ {

        # WebP

        set $base $1;

        set $webp_uri $base$webp_suffix;

        set $root "/var/www/site.com/htdocs";

        root $root;

        add_header Vary Accept;

        if ( !-f $root$webp_uri ) {

                add_header X_WebP_SP_Miss $root$webp_uri;


        try_files $webp_uri $uri =404;


Problem: It is not working. Please let me know if there is something I'm doing wrong. Any help will be appreciated. Thanks

1 Answer

0 votes
by Expert

Hi jazibsawar,

I know nothing about WebP, but in my experience the order that Nginx rules are proccessed matters a lot. You can try putting your custom code in your nginx site.conf after and before (trial and error) the php and wp "includes" configurations.


Welcome to the Community site for Webinoly.

If you have a question about Webinoly, please ask in English or Spanish.

To report a bug, please ask a question here with the bug tag.

News: Now you can use any external SMTP service in your server. All the server outgoing emails from any of your websites will be sent through this service.


Webinoly Support Paypal Donations Webinoly Support Bitcoin Donations

Your regular donations is what keep this project moving forward. If you like Webinoly, buy me a coffee or a beer to show support.

Affiliate Links

It is very important that any visitor to the site read the disclaimer, terms of use and privacy and legal statement before start browsing.