IT技术博客大学习 共学习 共进步
全部 移动开发 后端 数据库 AI 算法 安全 DevOps 前端 设计 开发者

利用nginx secure link module防盗链

阿熊的窝 2009-10-29 12:00:02 累计浏览 5,182 次
本机暂存

之前写过一篇blog是《利用lighttpd的mod_secdownload实现防盗链》,最近看到nginx也有类似功能,叫secure_link_module模块也试验了一把。

nginx需要打一个补丁才能实现跟lighttpd一样,通过时间戳来控制url过期。

1.给nginx打补丁,下载《nginx-secure-link-ttl》:

 
cd nginx-0.7.62
patch -p1 < ../nginx-secure-link-ttl.patch

2.编译nginx的时候加上“-with-http_secure_link_module”

3.配置nginx:

 
location /down/ {
            secure_link_secret "sbear.cn";  //密钥
            secure_link_ttl on;
            root /data/test/down;
            if ($secure_link = "") {
                return 403;
            }
            rewrite ^ /$secure_link break;
        }

4.php demo:

 
<?php
define(URL_TIMEOUT, 3600); //这里设置过期时间单位是秒
$prefix = "http://www.sbear.cn/down";
$protected_resource = "test.exe";
$secret = "sbear.cn";  //密钥
$time = pack('N', time() + URL_TIMEOUT);
$timeout = bin2hex($time);
$hashmac = md5( $protected_resource . $time . $secret );
$url = $prefix . "/" . $hashmac . $timeout . "/" . $protected_resource;
 
echo "<a href=" . $url . ">down</a>";
echo time();
?>

官方模块介绍:http://wiki.nginx.org/NginxHttpSecureLinkModule

同分类推荐文章

  1. Windows 95 defenses against installers that overwrite a file with an older version (2026-03-25 07:04:03)
  2. 提权实录:通过命名管道劫持可写服务 (2026-03-16 00:00:00)
  3. 黑盒视角下的 WebView 漏洞面探索 (2025-12-26 00:00:00)

查看更多 安全 文章 →

建议继续学习

  1. 配置Nginx+uwsgi更方便地部署python应用 (累计阅读 106,963)
  2. 搜狐闪电邮箱的 Nginx/Postfix 使用模式 (累计阅读 33,821)
  3. 记录一个软中断问题 (累计阅读 16,885)
  4. 解析nginx负载均衡 (累计阅读 16,503)
  5. server日志的路径分析 (累计阅读 11,181)
  6. Nginx模块开发入门 (累计阅读 11,101)
  7. 检查nginx配置,重载配置以及重启的方法 (累计阅读 10,781)
  8. Cacti 添加 Nginx 监控 (累计阅读 10,521)
  9. 使用Squid缓存视频 (累计阅读 10,280)
  10. fsockopen 异步处理 (累计阅读 10,280)