在 compile 時加入選項
root # ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_flv_module --with-http_ssl_module --with-http_secure_link_module
–with-http_secure_link_module 就可以使用這項功能
nginx.conf:
location ~ \.iso { secure_link $arg_ioo,$arg_isn; secure_link_md5 mycom$remote_addr$uri$arg_isn; if ($secure_link = "") { return 403; } if ($secure_link = "0") { return 403; } }
PHP example:
<?php $secret = 'mycom'; $client = $_SERVER['REMOTE_ADDR']; $path = '/intranet/install.iso'; $expire = time() + 30; // 30 秒後自動失效 $md5 = base64_encode(md5($secret . $client . $path . $expire, true)); $md5 = strtr($md5, '+/', '-_'); $md5 = str_replace('=', '', $md5); echo 'http://the.site' . $path . '?ioo=' . $md5 . '&isn=' . $expire . '<br />'; ?>
如此就可以解決盜連的問題了 ~