Question

How should nginx/conf.d/*.сonf?

I am new to the whole NGINX server so please ignore my complete ignorance.

I need to insert the following in the server context of blocks would be in /etc/nginx/conf.d/wordpress.conf so I can serve my images as webp can someone please just let me know how it should be. Ugh I feel like such a newb and that it’s right in front of me and I am just completely missing it.

location ~* "wp-content\/(uploads\/)(.*.(?:png|jpe?g))" {
  add_header Vary Accept;
  set $image_path $2;
  if (-f "/sites/plastiwin.com/files/wp-content/smush-webp/disable_smush_webp") {
    break;
  }
  if ($http_accept !~* "webp") {
    break;
  }
  try_files /wp-content/smush-webp/$image_path.webp $uri =404;
}

But I think I’m doing something wrong т-т.


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Hi @markinfinet,

In order to make your configuration work, you need to create the config file for your website plastiwin.com in /etc/nginx/sites-enabled/.

You can check this tutorial on STEP 5 to see how usually the config file is created:

https://www.digitalocean.com/community/tutorials/how-to-install-nginx-on-ubuntu-20-04#step-5-–-setting-up-server-blocks-recommended