小白求助:有一段代码,提示需要插入/nginx/sites-available,但搜索找不到这个文件?

“…Insert the following in the server context of your configuration file (usually found in /etc/nginx/sites-available). …”

有一段代码,提示需要插入/nginx/sites-available,但搜索找不到这个文件?

我应该插入那个文件下

麻烦详细描述一下具体问题。

是应用还是网站等。
1Panel 是容器化部署的应用,这点也需要注意。

用wordpress搭建的网站,安装一个网站图片优化的插件( Smush Pro),进行本地图片 local wedp 优化提示,需要把一段代码,插入nginx/sites-available文件

  1. Insert the following in the server context of your configuration file (usually found in /etc/nginx/sites-available). “The server context” refers to the part of the configuration that starts with “server {” and ends with the matching “}”.
    2、 Copy the generated code found below and paste it inside your HTTP or server blocks.

BEGIN SMUSH-WEBP

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

END SMUSH-WEBP

可以考虑进入网站设置页面,手动将上述配置添加到配置文件中,如图:

按照你的提示把上述代码,插入到server{}里了,还是不行,提示如下"Server configurations haven’t been applied yet. Make configurations to start serving images in WebP format."

你加完之后要是插件功能正常的话这个提示可以无视,因为php和nginx是在两个不同的容器,wordpress是扫描不到nginx的配置文件的