Fleximus Blog


Nginx is a great webserver that is flexible, feature rich and fairly well documented. But have you ever wanted to whitelist files upon their extensions and did not find a solution in the documentation reference? The bad answer is you will not find it. The good answer is: It is possible.

if ($request_filename !~* .(gif|html|jpe?g|png|ico|js|css|flv|swf|pdf|xml)$ ) {
  return 404;
The request filename is checked against that regular expression which looks for all endings of filenames you want. If it does not match, Nginx will display a 404 (not found) page. This snippet should be used in the config file before any other rewrite rules or checks. ■