I am moving a server to Nginx but I am new to it. Can you guide me how to restrict access to directory and sub directories?
I want to set a configuration to restrict access on /images and files in it. How can I do this?
Hello,
do you want to protect a folder with a login/password or you want to deny access to this folder ?
For a login/password protection, you can use htpasswd. To create your htpassword, you can use the following commands :
Bash:
# replace "yourpassword" to encrypt password with openssl,
ENCRYPTEDPASS=$(openssl passwd yourpassword)
# replace "youruser" with the username of your choice to create your htpasswd file
echo "youruser:$ENCRYPTEDPASS" > /etc/nginx/htpasswd
Then to protect a folder, add the following code in your nginx vhost :
Bash:
location /images {
satisfy any;
auth_basic "Restricted Area";
auth_basic_user_file htpasswd;
deny all;
}
It will be the same to deny access on this folder, but in this case just set
Code:
location /images { deny all; }