@bakhritdinov_b

Example nginx http secure link php?

Здравствуйте, хотел привязать прямой ссылки к ip с помощью модуль nginx http_secure_link.
nginx версия:
1.4.6

пример ссылки:
mp4.sitename.com/location/filename.mp4

php скрипт но никак не получается настроить nginx сервер к скрипту
/**
 * @param $baseUrl - non protected part of the URL including hostname, e.g. http://example.com
 * @param $path - protected path to the file, e.g. /downloads/myfile.zip
 * @param $secret - the shared secret with the nginx server. Keep this info secure!!!
 * @param $ttl - the number of seconds until this link expires
 * @param $userIp - ip of the user allowed to download
 * @return string
 */
function buildSecureLink($baseUrl, $path, $secret, $ttl, $userIp)
{
    $expires = time() + $ttl;
    $md5 = md5("$expires$path$userIp $secret", true);
    $md5 = base64_encode($md5);
    $md5 = strtr($md5, '+/', '-_');
    $md5 = str_replace('=', '', $md5);
    return $baseUrl . $path . '?md5=' . $md5 . '&expires=' . $expires;
}
// example usage
$secret = 'the_secret_key_configured_in_nginx';
$baseUrl = 'http://example.com';
$path = '/path/to/file.zip';
$ttl = 120; //no of seconds this link is active
$userIp = '195.99.99.99'; // normally you would read this from something like $_SERVER['REMOTE_ADDR'];
echo buildSecureLink($baseUrl, $path, $secret, $ttl, $userIp);


никак не получается подобрать подходящий конфигурацию nginx
для хранение файлов я использую субдомен. заранее спасибо за ответы
  • Вопрос задан
  • 2020 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы