location ~* ^/images/.+\.(png|jpg)$ { looks wrong – your images are not in a folder named “images”. Also, you might want to redirect jpegs with the “jpeg” extension (not just those with “jpg” extension).
I suggest this line instead.
location ~* ^/?wp-content/.*\.(png|jpe?g)$ {
If you haven’t already, please check out the I am on Nginx / OpenResty section in the FAQ
@roselldk thanks for help,
I try change location with your instructions, but no work.
I read all openresty, I try all steps, but no work.
Do you have any other suggestions to solve?
My Configs:
https://ibb.co/G25LyqG
https://ibb.co/fdm617Q
https://ibb.co/64GNNtQ
-
This reply was modified 6 years, 9 months ago by
knipers.
The try_files you are using are looking for webp’s in the same folder as the originals, but you have configured WebP Express to store them in a separate folder.
You can change the setting. But either way, you should add a line in the try_files which looks for webps in the separate folder, because the setting only applies to the images in the “upload” folder. For other images, the webps are stored in a separate folder.
You should add this line:
/wp-content/webp-express/webp-images/doc-root/$uri.webp
The following will look for existing webps in both places:
location ~* ^/?wp-content/.*\.(png|jpe?g)$ {
add_header Vary Accept;
if ($http_accept !~* "webp"){
break;
}
try_files
/wp-content/webp-express/webp-images/doc-root/$uri.webp
$uri.webp
;
}
I btw see that you have put the *map* in the http context. Perhaps it needs to be in the server context? Anyway, the solution above does not rely on the mapping.
@roselldk thanks for help, I was using “operation mode” as “varied images responses” on nginx, this operation mode does not work with nginx (I tried all possible configurations today all day long and believe none worked).
But I managed to solve by doing the following configuration:
– Operation mode: CDN Friendly
– Images types to convert: Both jpegs and pngs
– Destination Folder: Mingled
– File Extension: Append “.webp”
– Alter HTML (Checked) with default options
If possible, I suggest adding a new mode of operation named “Nginx” that sets these options by default and hides htaccess options and alerts.
This would help other users not to spend time with settings that will not work for nginx.
Good to hear that you made it work!
I btw updated the Nginx FAQ section to make it more readable.
Regarding better Nginx UI, I actually already have it on the roadmap 🙂 I do not plan to create a new operation mode, but I plan to make the UI reflect that it is Nginx. And I will add generation of nginx rules that matches the setup and settings (for display, ie when saving or clicking a “show nginx rules” button)