Question

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

Posted September 19, 2021 74 views
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/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 т-т.

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.

×
Submit an Answer
1 answer

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-%E2%80%93-setting-up-server-blocks-recommended

by Erin Glass
Nginx is one of the most popular web servers in the world and is responsible for hosting some of the largest and highest-traffic sites on the internet. In this guide, we'll discuss how to get Nginx installed on your Ubuntu 20.04 server.