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

  • Posted September 19, 2021
  • Nginx

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/") {
  if ($http_accept !~* "webp") {
  try_files /wp-content/smush-webp/$image_path.webp $uri =404;

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


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

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.

Hi @markinfinet,

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

You can check this tutorial on STEP 5 to see how usually the config file is created:–-setting-up-server-blocks-recommended