P
P
Pavel5682021-02-26 17:18:01
Nginx
Pavel568, 2021-02-26 17:18:01

How to change url in location of nginx config?

Hello! The question is this: it is necessary to change the extension of pictures to webp in the wp-content folder and in subfolders, now the extensions are changing starting from the parent public_html folder, here is the code (angle brackets replaced with%, otherwise it is filtered before publication):
map $http_accept $webp_ext {
default " ";
"~image\/webp" ".webp";
}

map $uri $file_ext {
default "";
"~(\.\w+)$" $1;
}

server {
location ~* "^(?%path%.+)\.(png|jpeg|jpg)$" {
try_files $path$webp_ext $path$file_ext =404;
}
you need to implement something like this:
location ~* "^(?%path%wp-content.+)\.(png|jpeg|jpg)$" {
try_files $path$webp_ext $path$file_ext =404;
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
ky0, 2021-02-26
@ky0

How to change url in location of nginx config?

With the help of the rewrite module .

D
dodo512, 2021-02-26
@dodo512

The string that location works with starts with c /
You just need to add /beforewp-content

location ~* "^(?<path>/wp-content.+)\.(png|jpeg|jpg)$"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question