Nginx 深刻- secure_link_module 模塊

參考連接nginx

  https://blog.csdn.net/u012525096/article/details/83578321bash

 

1: 資源下載 有效期app

 

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 directoryspa

yum install -y dos2unix
相關文章
相關標籤/搜索