小编Abd*_*afi的帖子

如何防止nginx中的图像盗链?

我正在尝试在 nginx 中实现图像热链接保护问题,我需要帮助。我有一个很大的问题,我的网站图像被提交到像 StumbleUpon 这样的社交网络,并带有像这样的直接链接

http://example.com/da.jpg

现在我想阻止对它们的访问,但我无法在 nginx.conf 文件中实现热链接预防。下面是我的 nginx.conf 文件,我应该将代码放在哪里?

要实现的盗链代码:

  location ~ \.(jpe?g|png|gif)$ {
    valid_referers none blocked example.com *.example.com;
    if ($invalid_referer) {
        return 403;
    }
}  
Run Code Online (Sandbox Code Playgroud)

我当前的代码如下

{

#user  nobody;
worker_processes  10;
worker_rlimit_nofile 81918;
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  81918;
    multi_accept on;
}


http {


    client_body_buffer_size 10K;
    client_header_buffer_size 1k;
    client_max_body_size 8m;
    large_client_header_buffers 2 1k;

    client_body_timeout   32;
    client_header_timeout 32;
    sendfile_max_chunk 512k;
    keepalive_timeout 5; # default 65
    send_timeout 20;     # default 60 …
Run Code Online (Sandbox Code Playgroud)

linux traffic nginx hotlinking

3
推荐指数
1
解决办法
7136
查看次数

标签 统计

hotlinking ×1

linux ×1

nginx ×1

traffic ×1