# Serve WebP images with Nginx and EWWW (RunCloud)

URL: https://wp24x7.com/webp-images-in-runcloud-nginx-ewww/
Updated: 2026-11-29
Type: blog post
Audience: WordPress site owners and sysadmins on Nginx or RunCloud

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

## Key facts

- 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.**

> **Quick answer**
Back up the server config and test on staging. A mistake in Nginx config can take sites offline, so run `nginx -t` before every reload.

## 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:

```php
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?

### RunCloud
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.
### Plain Nginx
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 nginx
```

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

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

**Want images, caching and server config looked at together?**
Our engineers can set it up for you.
[Post a project](/post-project)
[WordPress speed optimization](/wordpress-speed-optimization)

See our [support team](/wordpress-support), and for a related fix, [native lazy loading not working](/how-to-fix-native-lazy-loading-of-iframe-or-image-not-working).

## Frequently asked questions

### 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.

### 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.

### 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.

### 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.

### 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.

### 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.

### 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.

### 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.

### 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.

### 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.

### 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.
