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

Posted September 19, 2021 74 views

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 т-т.

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 in /etc/nginx/sites-enabled/.

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

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.