Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Nginx lists directories and files and uses passwords to control how access is configured

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly explains "Nginx lists directories and files and uses passwords to control how to configure access". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "Nginx lists directories and files and uses passwords to control how to configure access."

Use nginx to list directories

Preparation-install nginx and create some directories and files:

The copy code is as follows:

$sudo apt-get install nginx

$cd / usr/share/nginx

$mkdir web

$sudo mkdir directory {1pm 2pm 3}

$sudo touch file {1pm 2pm 3}

$ls

Directory1 directory2 directory3 file1 file2 file3

Nginx configuration:

The copy code is as follows:

$sudo vim / etc/nginx/conf.d/list.conf

Server {

Listen 80

Server_name 192.168.1.201

Root / usr/share/nginx/web

Index index.html

Autoindex on

Autoindex_exact_size off

Autoindex_localtime on

}

$sudo service nginx restart/reload

When accessing http://192.168.1.201, the screen displays:

You can use the web server to share files now; but only if there are no index.html files in the root directory.

Authorize access to the specified directory

Some directories do not want everyone to see, and can only be accessed after the specified user enters a password. For example, directory can only be accessed by test1:

Step1 install htpasswd

The copy code is as follows:

$sudo apt-get install apache2-utils

Step2 creates a password file

The copy code is as follows:

$sudo htpasswd-c / home/test/.htpasswd test1

New password:

Re-type new password:

Adding password for user test1

Step3 modifies nginx configuration file

The copy code is as follows:

$sudo vim / etc/nginx/conf.d/list.conf

Server {

Listen 80

Server_name 192.168.1.201

Root / usr/share/nginx/web

Index index.html

Autoindex on

Autoindex_exact_size off

Autoindex_localtime on

Location ^ ~ / directory1/ {

Auth_basic "input you user name and password"

Auth_basic_user_file / home/test/.htpasswd

}

}

After restarting the nginx service, you will be prompted to enter login information when you access the directory1 directory:

At this point, I believe that everyone has a deeper understanding of "Nginx lists directories and files and uses passwords to control how to configure access". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report