-1

I have a proxy_pass for a backend, but in this context, I should serve some static files that are stored in a directory. I`ve tried this:

server {
    listen 8180;
    location ~ ^/Backend?.(gif|jpg|png|jpeg|pdf|xls|xlsx)$ {
        root /data/images;
    }
    location /Backend {
        proxy_pass http://docker-conciliador;
    }
}

But when I try the URL /Backend/12345.jpg for example it didn`t work.

How can I make a regex for a specific location having this location a proxy_pass too???

1 Answers1

0

You regex ^/Backend?.(gif|jpg|png|jpeg|pdf|xls|xlsx)$ is incorrect and would match things like:

  • /BackendAgif
  • /BackenBjpg

Because ? stands for "match once or none" so it really reads as "d" or none. The dot . is for any one single character.

Correct would be:

    location ~ ^/Backend/.*\.(gif|jpg|png|jpeg|pdf|xls|xlsx)$ {
        root /data/images;
    }

There, .* is for any character, none or any number. The \. is dot (escaped).

Danila Vershinin
  • 5,286
  • 5
  • 17
  • 21
  • If I access http://localhost:8180/Backend/1226539622.jpg I get a 404 status. I`ve tried: location ~ ^/Backend/.*\.(gif|jpg|png|jpeg|pdf|xls|xlsx)$ { root /data/images; } – Anderson Faria Silva Feb 07 '21 at 01:57