In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces the relevant knowledge of how to configure Nginx access restrictions, the content is detailed and easy to understand, the operation is simple and quick, and has a certain reference value. I believe you will gain something after reading this article on how to configure Nginx access restrictions. Let's take a look.
What is nginx access restriction configuration
Nginx access restrictions can be based on two aspects, one is ip-based access control, and the other is user trust login control.
Below, we will introduce these two methods one by one.
Introduction to ip-based access control:
By configuring ip-based access control, some ip can be accessed and which ip can not be accessed.
This is the configuration method that allows access
Configuration syntax: allow address | cidr | unix | all
Default configuration: no configuration
Configuration path: http, server, location, limit_except
This is a configuration that does not allow access
Method configuration syntax: deny address | cidr | unix | all
Default configuration: no configuration
Configuration path: http, server, location, limit_except
Testing based on ip access restrictions
1. Check the local ip address. If it is a public network, check it on ip138. If it is an experiment, use cmd to check.
two。 Add an admin.html file to the / opt/app/code/ directory, which is a normal admin page with a background color
3. In the / etc/nginx/conf.d/ directory, modify the default.conf file by adding the following
As you can see from the figure above, a location is added to match admin.html, and a configuration based on ip restrictions is set to restrict 192.xx.xx.xx from access, and others can be accessed.
4. Reload nginx
5. Enter the URL in the browser to view the log
6. From the figure above, it has been implemented to restrict the access of a certain ip. If only a certain ip is allowed, you only need to change the keyword.
Example:
1. Server global ip limit
# vi nginx.conf allow 10.115.0.116; # allowed ip deny all
Site-limited ip
# vi vhosts.conf site global limit ip:location / {index index.html index.htm index.php; allow 10.115.0.116; deny all
Site directory restrictions
Location ^ ~ / test/ {allow 10.115.0.116; deny all
Access control based on login user trust
For example, when we access apache information, a user password box pops up to perform a pre-access authentication.
Configuration syntax: auth_basic string | off
Default configuration: auth_basic off
Configuration path: http, server, location, limit_except
Match configuration syntax: auth_basic_user_file filepath
Match default configuration: no configuration
Match configuration paths: http, server, location, limit_except
1. You need to add an identity file, the auth_conf file, which uses a htpasswd tool
Use the command htpasswd-c. / auth_conf root
Explain: htpasswd command-c: the default is to use md5 encryption,. / auth_conf is the specified path and file, and root is the user name.
After entering, the password will be entered twice.
two。 Modify the default.conf configuration file as follows
3. Reload nginx
4. Enter the URL, view the results, and you can see that you need to enter identity information before you can access
This is the end of the article on "how to configure Nginx access restrictions". Thank you for reading! I believe you all have a certain understanding of the knowledge of "how to configure Nginx access restrictions". If you want to learn more, you are welcome to follow the industry information channel.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.