Nginx restrict access to directory?

Kaz Wolfe

Well-known member
Joined
Jul 7, 2016
Messages
199
Best answers
0
Ratings
7
Points
18
#1
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?
 

hostens

Well-known member
Joined
Jan 18, 2017
Messages
118
Best answers
1
Ratings
28 5
Points
28
#2
In order to make a restriction, you can try "deny all" and deny the access into a specific directory. An example can be found here.

This should be done in the nginx configuration file.
 

VirtuBox

Global Mod
Staff Member
Joined
May 3, 2016
Messages
1,454
Best answers
3
Ratings
347 7
Points
83
#3
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; }
 
Older Threads
Replies
7
Views
71
Replies
3
Views
28
Replies
2
Views
22
fwh
Replies
4
Views
48
Newer Threads
Replies
6
Views
39
Replies
5
Views
33
Replies
5
Views
40
Replies
6
Views
57
Latest Threads
Recommended Threads
Similar Threads
Replies
4
Views
77
Replies
5
Views
119
Replies
8
Views
151

Latest postsNew threads

Latest Hosting OffersNew Reviews

Web Hosting

Most Likes - Past 30 Days

Tag Cloud

You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an alternative browser.