D
D
dieselbox2013-01-28 17:22:52
Nginx
dieselbox, 2013-01-28 17:22:52

Nginx doesn't respect link parameters in subrequests?

I use zip_mod in Nginx to create dynamic archives from files that are located on different physical servers. With something like this code, I send headers to Nginx so that it collects everything in one heap from sent to the user:

<?php
header('Content-Disposition: attachment; filename=' . $archiveName);
header('X-Archive-Files: zip');
echo implode("\r\n", $zip_files) . "\r\n";
exit();

The $zip_files array is something like this:
array(4) {
  [0] => string(140) "15263b8b 66000 /remote/127.0.1.1/files/private/ee4b41adb859ccce6be2fa0c45fc64f0.ini?name=php.ini&s=opPmjEJg5puHNciYvcRTeA,1359385713 php.ini"
  [1] => string(170) "bc8706b1 8361107 /remote/127.0.1.1/files/private/154eeb7eef9e55ce2da97d9f7cd6fee5.zip?name=nginx-1.2.6-build.zip&s=yy_iJjDxnCaix-tzDlrZ0Q,1359385713 nginx-1.2.6-build.zip"
  [2] => string(157) "9e7b9349 917698 /remote/127.0.1.1/files/private/597d93a30395e27a1f19f7e226187163.sql?name=tariff_dump.sql&s=Ob-V3hljvYODh0XVFU9dKQ,1359385713 tariff_dump.sql"
  [3] => string(145) "e7310915 225234 /remote/127.0.1.1/files/private/350679e790a7f702a5d37bee444de9f3.jpg?name=other.jpg&s=cHEvdSj5lU__35Utl8IRkg,1359385713 other.jpg"
}

The following is written in the Nginx config of the domain for processing external resources:
location ~* ^/remote/(.+?)/(.+)$ {
  internal;
  proxy_hide_header Content-Type;
  proxy_pass http://$1/$2;
}

This scheme works fine if file links do not have parameters, for example:
127.0.1.1/files/private/ee4b41adb859ccce6be2fa0c45fc64f0.ini

But if the link has parameters, like:
127.0.1.1/files/private/ee4b41adb859ccce6be2fa0c45fc64f0.ini?name=php.ini&s=opPmjEJg5puHNciYvcRTeA,1359385713

, then in this case Nginx sends subrequests that do not take these parameters into account. So instead of asking:
127.0.1.1/files/private/ee4b41adb859ccce6be2fa0c45fc64f0.ini?name=php.ini&s=opPmjEJg5puHNciYvcRTeA,1359385713

makes a request:
127.0.1.1/files/private/ee4b41adb859ccce6be2fa0c45fc64f0.ini

The question is, how can you avoid Nginx from discarding link parameters?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
D
Dmitry T., 2013-01-28
@tyzhnenko

Try using the $args variable.
Something like:

proxy_pass http://$1/$2?$args

G
gvsmirnov, 2013-01-28
@gvsmirnov

Options are available in a variable $args.

A
Andrew, 2013-01-28
@Morfi

The module should write to the log
github.com/evanmiller/mod_zip/blob/master/ngx_http_zip_module.c#L564
Look at the log

D
dieselbox, 2013-01-29
@dieselbox

Thanks for answers. Works with this config:

    location ~* ^/remote/(.+?)/(.+)$ { # proxied download from storage
      internal;
      proxy_hide_header Content-Type; # correct Content-Type is set by backend
      proxy_pass http://$1/$2?$args;
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question