参考链接
https://blog.csdn.net/u012525096/article/details/83578321
1: 资源下载 有效期
server { listen 80; server_name localhost; #charset koi8-r; #access_log /var/log/nginx/log/host.access.log main; root /opt/app/code; location / { secure_link $arg_md5,$arg_expires; secure_link_md5 "$secure_link_expires$uri imooc"; #注意此处的加密串imooc if ($secure_link = "") { #若字串不符合 return 403; } if ($secure_link = "0") { #若国企返回410 gone return 410; } }
}
2: md5.sh
#!/bin/sh # #Auth:Jeson@imoocc.com servername="120.79.210.194" download_file="/download/file.png" time_num=$(date -d "2019-07-23 00:00:00" +%s) #过期时间 secret_num="imooc" #此处的加密串 和上面一致 res=$(echo -n "${time_num}${download_file} ${secret_num}"|openssl md5 -binary | openssl base64 | tr +/ -_ | tr -d =) echo "http://${servername}${download_file}?md5=${res}&expires=${time_num}"
若执行报错, -bash: xxx: /bin/sh^M: bad interpreter: No such file or directory
yum install -y dos2unix