A
A
Artem Ershov2018-12-11 12:43:44
Nginx
Artem Ershov, 2018-12-11 12:43:44

Why can Bad Request crash if there is a space in the name?

There is such piece of a configuration.

location ~* ^/.+\.(webp)$ {
        expires max;
        etag on;
      try_files $uri $uri/ /try_image.cgi?source=$uri;
    	}

If there is a webp file, then we give it away, if not, we give it to the $uri bash script, which will prepare and give the missing file. The problem is that if a file with a space in the name comes across, then nginx returns a Bad Request.
That is, ' htр://domen.xyz/image_name.jpg.webp ' in the absence of a webp file is processed normally, but ' httр://domen.xyz/image name.jpg.webp ' (' httр://domen .xyz/image%20name.jpg.webp ' ) returns a Bad Request

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dodo512, 2018-12-12
@artemerschow

location ~* ^/.+\.(webp)$ {
    expires max;
    etag on;
    try_files $uri $uri/ @handler;
}

location @handler {
    rewrite ^(.*)$ /try_image.cgi?source=$1;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question