NGINX Servers
-
Does this plugin support NGINX servers, I see that it alters .htaccess, but NGINX doesn’t use those.
-
You’re right — the current
atec-webp.htaccessrules go beyond simple WebP file rewrites. They include:- MIME type definition
- Cache Vary headers (for Accept-Encoding and Accept)
- Three rewrite layers:
- Serving
.Xwebp.webp(e.g., optimized variants), - Falling back to
.webp, - Fallback conversion via
img2webp.php.
- Serving
This layered setup allows compatibility and graceful degradation — but yes, it’s all Apache-specific.
Serve .webp images when the browser supports it
location ~* ^(.+).(jpe?g|png|gif|bmp)$ {
set $img_uri $uri;
💡 Equivalent NGINX ConfigurationHere’s how you could manually replicate this behavior on NGINX:
# Serve .webp images when the browser supports it
location ~* ^(.+)\.(jpe?g|png|gif|bmp)$ {
set $img_uri $uri;
# 1. Serve .Xwebp.webp if it exists
set $webp_x "$img_uri.Xwebp.webp";
if (-f $document_root$webp_x) {
add_header Vary "Accept";
add_header Content-Type image/webp;
return 200 $webp_x;
}
# 2. Serve .webp if it exists
set $webp "$img_uri.webp";
if (-f $document_root$webp) {
add_header Vary "Accept";
add_header Content-Type image/webp;
return 200 $webp;
}
# 3. Otherwise, fallback to converter
rewrite ^(.+\.(jpe?g|png|gif|bmp))$ /wp-content/plugins/atec-webp/img2webp.php?src=$1 last;
}Notes:
- This assumes WordPress is installed at the web root.
- You might need to adjust
/wp-content/plugins/...if you’re using symlinks or a custom plugin directory. - The MIME type for
.webpis usually already handled by modern NGINX builds, but if not:
types {
image/webp webp;
}Summary
✅ Yes,
atec-webpworks with NGINX, but you need to manually replicate the rewrite rules in your server config.🚫 The plugin does not automatically configure NGINX, because NGINX doesn’t support runtime config editing (like
.htaccess).Thanks a lot for the reply.
I just wanted to know, does that configuration offer the same functionality as the Apache specific rewrites?
I really like the features of this plugin so I might even consider switching.
I have not tested the NGINX config. But yes it is basically the same. It makes the server deliver .webp if exists. If not, the requet is routed to the build script. On the next request, when .webp was created, it is delivered directly.
Let me know if it works.
Sorry, I just recently was able to test it and couldn’t get it to work.
Possibly because I’m behind cloudflare, although I’m just using it for DNS.
You probably have it running but if you use CF, your server will never get a “accept webp” header on a not webp file. But atec-webp will only return webp if request header says webp is supported. atec-webp works but CF prevents it from getting into the route.
The topic ‘NGINX Servers’ is closed to new replies.