14. Nginx Secure Link

Check the legality of the request for resources

  server {
        listen 3300;
        server_name www.siguoya.name;
        root /usr/local/nginx/1.12.1/html;
        location / {
            secure_link $arg_md5,$arg_expires;
            secure_link_md5 "$secure_link_expires$uri siguoya";
            if ($secure_link = "") {
                return 403;
            }
            if ($secure_link = "0") {
                return 410;
            }
        }
    }

If you are accessing http://www.siguoya.name:3300/index.html?expires=111it, shell md5 values calculated as follows:

echo -n '111/index.html siguoya' | openssl md5 -binary | openssl base64 | tr +/ -_ | tr -d =
link Response Code
http://www.siguoya.name:3300/index.html?expires=111&md5=111 403, md5 incorrect time expired
http://www.siguoya.name:3300/index.html?expires=2147483647&md5=111 403, md5 is not correct, time has not expired
http://www.siguoya.name:3300/index.html?expires=111&md5=cLdY2ROg2kZDD0xkWaJ8TQ 410, md5 correct time expired
http://www.siguoya.name:3300/index.html?expires=2147483647&md5=GfmT6Hj3U55xfQJ3aNqjfQ 200, md5 correct, time has not expired

Read topics

Guess you like

Origin www.cnblogs.com/zy108830/p/12600372.html