nginx-lua-ds-hotlink防盜鏈系統(tǒng)
基于nginx和lua的防盜鏈系統(tǒng)
A Prevent Hotlinking System based on nginx and lua
將代碼放在位于nginx根目錄下的lua/ds_hotlink/下
Put the code into the directory lua/ds_hotlink which is located in the root directory of the nginx
在nginx.conf的http段中添加如下配置:
Add the config below to the http seg in nginx.conf:
lua_package_path "/u/nginx/lua/ds_hotlink/?.lua;;"; init_by_lua_file lua/ds_hotlink/init.lua;
配置如下location用于獲取訪問key
Add the config below to /get_key location for geting access key
location = /get_key {
allow 10.0.2.2;
deny all;
content_by_lua_file lua/ds_hotlink/get_key.lua;
}
在需要防盜鏈的location下配置如下
Add the config below to a location which need to prevent hotlinking
access_by_lua_file lua/ds_hotlink/refer.lua;
或者配置如下
Alternative config below
access_by_lua_file lua/ds_hotlink/accesskey.lua;
防盜鏈相關(guān)的配置在config.lua中,需要保證nginx的worker process對(duì)日志文件有讀寫權(quán)限
You can config Prevent Hotlinking System with the file config.lua,and you must make the worker process of nginx have the read and write permission to the log file
評(píng)論
圖片
表情
