2019-05-15 nginx 使用变量实现防盗链

[root@hk sbin]#./nginx  -V
nginx version: nginx/1.14.2
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC) 
built with OpenSSL 1.0.2k-fips  26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/data/nginx --with-http_ssl_module --with-http_secure_link_module   #要编译安装with-http_secure_link_module模块

 server {
        listen       80;
        server_name  secure.aaa.com;
       location /p {
            secure_link_secret mysecret; #设置一个秘钥为mysecret
            if ($secure_link = "") {   #$secure_link为md5值
              return 403;
          }
            rewrite ^ /secure/$secure_link;  #当访问p路径时重定向到/secure/$secure_link  #$secure_link为md5值,是访问的uri和mysecret的md5值
         }
        location /secure {
             alias html;  #此目录下有index.html
             internal;
        }
}
echo -n "index.htmlmysecret" |md5sum  求出md5值为42166c69bd0439cfa8d338a9f671d83e

http://secure.zhangdazhi.com/p/42166c69bd0439cfa8d338a9f671d83e/index.html #浏览器访问此url才能访问

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容