Useful Snippets


This blog is used to collect useful snippets related to Linux, PHP, MySQL and more. Feel free to post comments with improvements or questions!

RSS Latest posts from my personal blog

Most viewed posts

Subscribe to RSS feed

Nginx configuration for the WebP Converter for Media WordPress plugin

Stanislav KhromovStanislav Khromov

To make Nginx work with the WebP Converter for Media you can use the configuration below. It checks if the the browser Accept header allows WebP images and serves the WebP image if that is the case. If the browser does not support it, the original jpg, png or gif is served.

You will need to place the configuration in the server block of your existing configuration and then configure the plugin to use the “via .htaccess (recommended)” method. Even though we don’t use Apache our method works the same as the plugins .htaccess method.

server {
    // ... 

    # Add support for "WebP Converter for Media" WordPress plugin
    location ~ ^/wp-content/(?<path>.+)\.(?<ext>jpe?g|png|gif)$ {
        if ($http_accept !~* "image/webp") {

        expires 180d;
        add_header Vary Accept;
        try_files /wp-content/uploads-webpc/$path.$ext.webp $uri =404;
    // ...

If you want to see a more complete example, please see here.

Web Developer at Aftonbladet (Schibsted Media Group)
Any opinions on this blog are my own and do not reflect the views of my employer.
Twitter Profile
Visit my other blog

Comments 0
There are currently no comments.