Skip to content
Performance

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.

By WP24×7 engineers4 min readPublished August 6, 2021Updated November 29, 2026

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

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.

ApproachNeeds server changes?Note
WordPress 6.1+ WebP outputNoNew uploads only
EWWW picture tags or JavaScriptNoPlays well with CDNs
Nginx rulesYesExisting 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.

Smaller files, chosen by the browser's Accept header

How do I add it?

  1. Open your server, then the web application, and go to NGINX Config.
  2. Click Create Config, choose to write your own, and select type location.http (included in the http context). Name it and paste the map block.
  3. Create a second config of type location.static (included in the server block for static files) and paste the location block.
  4. Save. RunCloud validates and reloads Nginx. If it reports an error, correct the snippet first.

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-type

Replace 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?

ProblemWhyFix
CDN serves the wrong formatThe CDN caches by URL alone and does not vary by AcceptUse the CDN's own image feature, the picture-tag method, or bypass cache for images
WebP files missingtry_files falls back to the originalNo error, just no saving; run Bulk Optimize
Hotlinks or backup pluginsThey expect the original formatTest them
Disk spaceTwo copies of every imagePlan 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.

Want images, caching and server config looked at together?

Our engineers can set it up for you.

See our support team, and for a related fix, native lazy loading not working.

FAQ

Questions people ask

11 answers. Can't find yours? Ask an engineer.

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 answer
Will 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 answer
Why 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 answer
Can 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 answer
How 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 answer
Where 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 answer
How 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 answer
Why 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 answer
How 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 answer
How 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 answer
Will 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 answer

Keep reading

Want an engineer on it?

Tell us what is wrong in plain words. A person reads it, today.