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 web website access restrictions login verification

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

In some businesses can not be directly provided to outsiders to view, can only specify some people to view. For security reasons, limit access to ip and do a simple login page authentication on the page.

The operation is very simple, make a simple record here, so that you can check the memories later.

Operating system CentOS 7.2

Nignx 1.10.1

First of all, we use Nginx to provide the Basic Auth function of HTTP, and configure the user name and password that need to be entered before we can access the website.

When we use htpasswd to generate password information, we need to install httpd-tools first, because the htpasswd command is included in httpd-tools

We need to use the htpasswd command in httpd-tools to set the account password

There is usually a httpd installed. If not, install yum install-y httpd-tools.

Check if httpd-tools is installed on the local server

$rpm-qa | grep httpd-toolshttpd-tools-2.4.6-45.el7.centos.4.x86_64

Next, create an account password.

$htpasswd-c / data0/work/nginx/passwd.db testNew password: Re-type new password: Adding password for user test

Check to see if the creation is successful

$cat / data0/work/nginx/passwd.dbtest:$apr1 $QroBUTZr$UNtXwv5nS3/jtvTCIw96h/

It is found that the account already exists and is an encrypted non-plaintext password.

Then we will add settings in the nginx configuration file.

$vim / data0/work/nginx/conf/nginx.confserver {listen 80; server_name test.xxx.com; charset utf-8; auth_basic "secrect"; # # plus auth_basic_user_file / data0/work/nginx/passwd.db; # # plus location / {root / data0/work/nginx/html/; index index.html # # limit ip allow 39.28.0 to accessible websites; allow 47.29.0 to 16; allow 120.83.0 to 16; allow 202.6.0 to 16; deny all;}}

Verify that nginx is configured incorrectly

$/ data0/work/nginx/sbin/nginx-tnginx: the configuration file / data0/work/nginx/conf/nginx.conf syntax is oknginx: configuration file / data0/work/nginx/conf/nginx.conf test is successful

If there is no problem, reload the nginx service

$/ data0/work/nginx/sbin/nginx-s reload

Visit the website page and you will jump out of authentication.

If you visit the website with the wrong account or password, you will not be able to get in. after you cancel the login, the following screen will pop up.

Unspecified access to the ip to access the website, directly denied access.

From the above results, the setting meets the requirements, and the setting is successful!

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

Servers

Wechat

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

12
Report