Serve WebP images with Nginx and EWWW (RunCloud)
Serve WebP versions of JPG and PNG from Nginx with EWWW Image Optimizer, with RunCloud config steps, a test command and CDN caching cautions.
At a glance
WebP files are usually noticeably smaller than JPG or PNG at similar quality. EWWW Image Optimizer can create them, and on Nginx a map on the Accept header plus a try_files rule serves image.jpg.webp to browsers that accept WebP and image.jpg to everyone else. This guide covers the rules, RunCloud config steps, a curl test and the CDN caching cautions.
Updated November 29, 2026 · For WordPress site owners and sysadmins on Nginx or RunCloud
- For site owners and sysadmins serving WebP from Nginx with EWWW Image Optimizer
- Rule a map on $http_accept plus try_files $uri$webp_suffix $uri =404
- File naming photo.jpg becomes photo.jpg.webp in the same folder
- Alternatives WordPress 6.1 WebP output, EWWW picture tags, no server changes
- Test curl with and without an Accept: image/webp header
- Risk CDNs that do not vary by Accept can serve the wrong format
- Safety back up config, run nginx -t before every reload
On this page
WebP files are usually noticeably smaller than JPG or PNG at similar visual quality. EWWW Image Optimizer can create them, but your server also needs to decide which version to send. On Nginx, a `map` on the `Accept` header plus a `try_files` rule serves `image.jpg.webp` to browsers that accept WebP and `image.jpg` to everyone else.
Do I even need server rules?
No. Start with the simplest approach that works.
| Approach | Needs server changes? | Note |
|---|---|---|
| WordPress 6.1+ WebP output | No | New uploads only |
| EWWW picture tags or JavaScript | No | Plays well with CDNs |
| Nginx rules | Yes | Existing URLs stay the same with no HTML changes |
WordPress accepts WebP uploads from 5.8 and can create WebP sub-sizes from JPG uploads since 6.1. A small filter makes new uploads WebP:
add_filter( 'image_editor_output_format', function ( $formats ) {
$formats['image/jpeg'] = 'image/webp';
return $formats;
} );Visitors need a WebP-capable browser, which today is essentially all of them.
How does the Nginx rule work?
EWWW saves a WebP copy next to each original, appending the extension: photo.jpg becomes photo.jpg.webp. The rule checks whether the browser's Accept header mentions WebP and, if so, tries the .webp file first.
First, a map placed at the http level:
map $http_accept $webp_suffix {
default "";
"~*webp" ".webp";
}Then, in the server block, a location for images:
location ~* ^.+\.(png|jpe?g)$ {
add_header Vary Accept;
try_files $uri$webp_suffix $uri =404;
}For browsers sending Accept: image/webp, $webp_suffix is .webp, so Nginx tries /uploads/photo.jpg.webp and falls back to /uploads/photo.jpg. The Vary: Accept header tells caches the response depends on that header.
How do I add it?
- Open your server, then the web application, and go to NGINX Config.
- Click Create Config, choose to write your own, and select type location.http (included in the
httpcontext). Name it and paste themapblock. - Create a second config of type location.static (included in the server block for static files) and paste the
locationblock. - Save. RunCloud validates and reloads Nginx. If it reports an error, correct the snippet first.
Put the map in /etc/nginx/conf.d/webp.conf and the location in your site's server file, then run:
sudo nginx -t && sudo systemctl reload nginxIf your site already has a location for image types with its own caching headers, merge the lines instead of adding a second regex block, since Nginx uses the first matching regex.
How do I generate the WebP files?
In Settings, EWWW Image Optimizer, WebP Conversion, enable WebP conversion, then use Bulk Optimize to create files for your existing library. New uploads convert automatically. Confirm your folder contains both photo.jpg and photo.jpg.webp. If the names differ, for example photo.webp, adjust the rule or use the picture-tag method.
How do I test it?
Use curl and look at the response headers:
curl -sI -H "Accept: image/webp" https://example.com/wp-content/uploads/2026/01/photo.jpg | grep -i -E "content-type|vary"
curl -sI https://example.com/wp-content/uploads/2026/01/photo.jpg | grep -i content-typeReplace the URL with a real image on your site. The first should return content-type: image/webp and vary: Accept, and the second image/jpeg. In the browser, open DevTools, the Network tab, filter by Img and check the Type column.
What can go wrong?
| Problem | Why | Fix |
|---|---|---|
| CDN serves the wrong format | The CDN caches by URL alone and does not vary by Accept | Use the CDN's own image feature, the picture-tag method, or bypass cache for images |
| WebP files missing | try_files falls back to the original | No error, just no saving; run Bulk Optimize |
| Hotlinks or backup plugins | They expect the original format | Test them |
| Disk space | Two copies of every image | Plan for it |
Cloudflare, for instance, does not generally vary cached responses by Accept for ordinary caching, so test through your CDN, not just the origin.
How do I roll back, and will it speed up my site?
Delete the two RunCloud config entries, or remove the include lines in plain Nginx, run nginx -t and reload. The WebP files stay on disk and do no harm. Clear every cache layer, including the CDN, before concluding it is reverted.
Image weight is a common cause of slow pages, but check your largest images first and measure with PageSpeed Insights or WebPageTest before and after.
Our engineers can set it up for you.
See our support team, and for a related fix, native lazy loading not working.
Do I need Nginx rules to serve WebP with EWWW?
Not always. EWWW offers rewrite methods inside WordPress, such as picture tags, that need no server changes. Nginx rules let the server swap files without touching your HTML.
Link to this answerWill old browsers break?
The rule sends WebP only to browsers that say they accept it in the Accept header, and the original file to everyone else.
Link to this answerWhy do I see the JPG even though WebP exists?
Usually the Accept header is not reaching the origin, a CDN has cached the JPG for all visitors, or the WebP file names do not match what the rule expects.
Link to this answerCan WordPress create WebP without a plugin?
WordPress 5.8 accepts WebP uploads and 6.1 can create WebP sub-sizes from JPG uploads. A small image_editor_output_format filter makes new uploads WebP. It affects new uploads only.
Link to this answerHow does EWWW name the WebP files?
It saves a copy next to each original with the extension appended, so photo.jpg becomes photo.jpg.webp. If your files are named photo.webp instead, adjust the rule or use the picture-tag method.
Link to this answerWhere do I add the config in RunCloud?
In the web application's NGINX Config, create a custom config of type location.http for the map block and another of type location.static for the location block. RunCloud validates and reloads Nginx.
Link to this answerHow do I test the rule?
Use curl -sI with an Accept: image/webp header against a real image URL and check for content-type image/webp and vary: Accept, then without the header and check for image/jpeg. In the browser, filter the Network tab by Img and read the Type column.
Link to this answerWhy is Vary: Accept needed?
It tells caches the response depends on the Accept header, so a cache does not hand one format to every visitor.
Link to this answerHow do I generate WebP for my existing library?
In EWWW's WebP Conversion settings enable conversion, then use Bulk Optimize to create files for existing images. New uploads convert automatically.
Link to this answerHow do I roll the change back?
Delete the two RunCloud config entries or remove the include lines, run nginx -t and reload. The WebP files stay on disk and do no harm. Clear every cache layer, including the CDN, before concluding it is reverted.
Link to this answerWill WebP speed up my site?
Image weight is a common cause of slow pages, but check what your largest images are first and measure before and after with PageSpeed Insights or WebPageTest.
Link to this answerKeep reading
Want an engineer on it?
Tell us what is wrong in plain words. A person reads it, today.