D
D
dieselbox2013-01-29 10:14:41
Nginx
dieselbox, 2013-01-29 10:14:41

Nginx and mod_zip: download files from external servers using domain name?

I'm doing the formation of a dynamic zip archive using the mod_zip module. The following config is used to download files from external servers (file-server1.local, file-server2.local ...). The formation of a dynamic archive is carried out approximately in the following code:

<?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 looks like this:
array(7) {
  [0] => string(140) "15263b8b 66000 /remote/file-server1.local/files/private/ee4b41adb859ccce6be2fa0c45fc64f0.ini?name=php.ini&s=QNaKDGtKbhi5f1ySB3LwpQ,1359444711 php.ini"
  [1] => string(170) "bc8706b1 8361107 /remote/file-server1.local/files/private/154eeb7eef9e55ce2da97d9f7cd6fee5.zip?name=nginx-1.2.6-build.zip&s=3VFP4YEG3I5bAuQH0tiYww,1359444711 nginx-1.2.6-build.zip"
  [2] => string(157) "9e7b9349 917698 /remote/file-server1.local/files/private/597d93a30395e27a1f19f7e226187163.sql?name=tariff_dump.sql&s=U0CdT7Z6n4AoGiZ3K6Qe2Q,1359444711 tariff_dump.sql"
  [3] => string(145) "e7310915 225234 /remote/file-server1.local/files/private/350679e790a7f702a5d37bee444de9f3.jpg?name=other.jpg&s=Fy4YD6rh5FMgvbSGn9Klzg,1359444711 other.jpg"
  [4] => string(101) "0a099d44 36459 /remote/file-server1.local/files/public/8b62108713f3e949d7a27cdb4d3f3e18?name=memcache memcache"
  [5] => string(286) "50208924 466588 /remote/file-server1.local/files/public/9e751852bdfcce582f193a893eb7ad65.jpg?name=%D1%80%D1%83%D1%81%D1%81%D0%BA%D0%BE%D0%B5_%D0%BD%D0%B0%D0%B7%D0%B2%D0%B0%D0%BD%D0%B8%D0%B5_%D0%B8%D0%B7%D0%BE%D0%B1%D1%80%D0%B0%D0%B6%D0%B5%D0%BD%D0%B8%D1%8F.jpg russkoe_nazvanie_izobrazheniya.jpg"
  [6] => string(116) "d67324f8 19 /remote/file-server1.local/files/public/30e64f83b137f0e1e26624bdcbc59912.php?name=test_script.php test_script.php"
}

The problem is that it is not possible to download a file by domain name. Downloading can be done only by ip-address. To do this, I convert the domain name to ip using the gethostbyname () function and get something like this array:
array(7) {
  [0] => string(140) "15263b8b 66000 /remote/127.0.1.1/files/private/ee4b41adb859ccce6be2fa0c45fc64f0.ini?name=php.ini&s=QNaKDGtKbhi5f1ySB3LwpQ,1359444711 php.ini"
  [1] => string(170) "bc8706b1 8361107 /remote/127.0.1.1/files/private/154eeb7eef9e55ce2da97d9f7cd6fee5.zip?name=nginx-1.2.6-build.zip&s=3VFP4YEG3I5bAuQH0tiYww,1359444711 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=U0CdT7Z6n4AoGiZ3K6Qe2Q,1359444711 tariff_dump.sql"
  [3] => string(145) "e7310915 225234 /remote/127.0.1.1/files/private/350679e790a7f702a5d37bee444de9f3.jpg?name=other.jpg&s=Fy4YD6rh5FMgvbSGn9Klzg,1359444711 other.jpg"
  [4] => string(101) "0a099d44 36459 /remote/127.0.1.1/files/public/8b62108713f3e949d7a27cdb4d3f3e18?name=memcache memcache"
  [5] => string(286) "50208924 466588 /remote/127.0.1.1/files/public/9e751852bdfcce582f193a893eb7ad65.jpg?name=%D1%80%D1%83%D1%81%D1%81%D0%BA%D0%BE%D0%B5_%D0%BD%D0%B0%D0%B7%D0%B2%D0%B0%D0%BD%D0%B8%D0%B5_%D0%B8%D0%B7%D0%BE%D0%B1%D1%80%D0%B0%D0%B6%D0%B5%D0%BD%D0%B8%D1%8F.jpg russkoe_nazvanie_izobrazheniya.jpg"
  [6] => string(116) "d67324f8 19 /remote/127.0.1.1/files/public/30e64f83b137f0e1e26624bdcbc59912.php?name=test_script.php test_script.php"
}

The nginx config for downloading files from external servers is as follows:
location ~* ^/remote/(.+?)/(.+)$ {
  internal;
  proxy_hide_header Content-Type;
  proxy_pass http://$1/$2?$args;
}

The question is: is it possible to somehow download files exactly by the domain name, since it is not always possible to organize such a structure so that each domain has a separate ip-address?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
dieselbox, 2013-01-29
@dieselbox

The server terminates the connection. This is what is in the logs: 2013/01/29 16:18:22 [error] 7023#0: *14 mod_zip: a
subrequest returned 502, aborting… while sending to client, client: 127.0.0.1
domain-based subqueries.

M
mayorovp, 2013-01-29
@mayorovp

And if so:

location ~* ^/remote/(.+?)/(.+?)/(.+)$ {
    internal;
    proxy_hide_header Content-Type;
    proxy_set_header Host $2;
    proxy_pass http://$1/$3?$args;
}

D
dieselbox, 2013-01-29
@dieselbox

The matter is that I cannot define on what file stumbles. As I understand it, some non-existent address is being formed, and falls off by timeout. Since the addresses are created non-existent, these requests are not displayed in the logs.
And then, as it were, on any particular file, waiting occurs - in principle, on any file, if you take any one of them. That is, something is wrong with the paths.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question