Skip to content

Instantly share code, notes, and snippets.

@hoangdh
Last active January 6, 2019 15:12
Show Gist options
  • Save hoangdh/7ac79a96e4188a5b76e89774f3f53a5d to your computer and use it in GitHub Desktop.
Save hoangdh/7ac79a96e4188a5b76e89774f3f53a5d to your computer and use it in GitHub Desktop.
Block access to mp4 files - NGINX

Với NGINX - Thêm vào file cấu hình

Không cho phép truy cập trực tiếp file MP4

location ~ \.mp4($|/) {
                return 301 http://google.com;
                allow 118.70.170.88;
                deny all;
         }
Tham khảo:

Không cho phép cURL, wget, FFMPEG

if ($http_user_agent ~* (wget|curl|Lavf) ) {
          return 202;
        }

Giới hạn Referer

Liệt kê danh sách referer không được phép (bên ngoài block server)

 map $http_referer $bad_referer {
                hostnames;
                default                           0;

                # Put regexes for undesired referers here
                "~hoang1.com"             1;
                "~hoang2.net"             1;
                "~hoang3.vn"              1;
        }

Thêm phần cấu hình từ chối:

 if ($bad_referer) {
            return 200;
        }

Với APACHE

Sử dụng .htaccess

<IfModule mod_rewrite.c>
RewriteRule (\.html)$ - [F,L,NC]
</IfModule>

Tham khảo:

Cấu hình NGINX nhận thư mục xác minh LE

location ^~ /.well-known/acme-challenge/ {
  		default_type "text/plain";
 		rewrite /.well-known/acme-challenge/(.*) /$1 break;
  		root /usr/share/nginx/html;
	}

-> Include vào mỗi VirtualHost

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment