Home > Back-end >  nginx proxy_pass download page from other host
nginx proxy_pass download page from other host

Time:02-12

I need to download pdf file from other host.

For example:

mydomain.com/bill/55d5e947-edc4-44e0-bee4-c5ffacaf81dd/download

must download pdf file from

domain.com/bill/55d5e947-edc4-44e0-bee4-c5ffacaf81dd/download

my location is below, may be i'm missing something?

         location "/bill/([0-9a-zA-Z]{8})-([0-9a-zA-Z]{4})-([0-9a-zA-Z]{4})-([0-9a-zA-Z]{4})-([0-9a-zA-Z]{12})/download" {
                proxy_pass http://10.130.0.31:8088;
                proxy_set_header content-type "application/pdf";

CodePudding user response:

Regex Location matching always starts with ~, ~* ~^ like

location ~ /bill/([0-9a-zA-Z]{8})-([0-9a-zA-Z]{4})-([0-9a-zA-Z]{4})-([0-9a-zA-Z]{4})-([0-9a-zA-Z]{12})/download {
...
}

Is your Regex correct? I mean technically it is BUT the ID in your location looks like a UUID? Could this be possible? As UUID are basically hex and as you are already spending the compute time to validate the UUID in the location you should use [a-f0-9] instead of [0-9a-zA-Z]. BUT JUST IF IT IS A UUID and not just like a Thing that looks like a UUID.

A working configuration will look like

 location ~ "/bill/([a-f0-9]{8})-([a-f0-9]{4})-([a-f0-9]{4})-([a-f0-9]{4})-([a-f0-9]{12})/download" {
                proxy_pass http://127.0.0.1:8000;
                proxy_set_header content-type "application/pdf";
}

  • Related