Nginx, close access to the folder

June 3, 2016 10 Yehor Rykhnov

A simple example of the closure of access to one or several folders using Nginx.

Analog deny from all in .htaccess

Close access to the one folder using Nginx

server {
    #...
    location ^~ /path/to/folder/ {
        deny all;
    }
    #...
}

Close access to several folders using Nginx

server {
    #...
    location ~* ^/(folder_1|folder_2)($|\/) {
        deny all;
    }
    #...
}

After making changes do not forget to restart the Nginx:

service nginx reload

or

service nginx restart