Skip to content

Instantly share code, notes, and snippets.

@oNguyenNgocTrung
Created January 22, 2019 17:17
Show Gist options
  • Save oNguyenNgocTrung/5cdda17a2a7b7b5d9889c56f01fb0c1e to your computer and use it in GitHub Desktop.
Save oNguyenNgocTrung/5cdda17a2a7b7b5d9889c56f01fb0c1e to your computer and use it in GitHub Desktop.
Deny Access File 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 192.167.1.1;
                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
                "~domain.com"             1;
                "~domain.net"             1;
                "~domain.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