Ordinary work, it is necessary to some specific pages to do user authentication, is logged in, to enter the user name and password before you can enter, so it is more secure.
So what does user authentication do? For specific operation, see
Enter the command cat/usr/local/apache2.4/conf/extra/httpd-vhosts.conf, view the contents of the file, and make sure to change the second VirtualHost virtual host, because the first virtual host is the default virtual host, regardless of it. Then enter the command vim/usr/local/apache2.4/conf/extra/httpd-vhosts.conf, enter, see,
Insert the contents of the red box, save and exit.
The contents of VirtualHost are as follows:
<virtualhost *:80>
DocumentRoot "/data/wwwroot/www.111.com"
ServerName 111.com
Serveralias www.example.com
<Directory/data/wwwroot/111.com>//Designation of certified directories
AllowOverride authconfig//This equivalent to open the authentication switch
AuthName "111.com user auth"//Custom certified name, not very useful
AuthType Basic//authentication type, generally basic, other types of Amin useless
AUTHUSERFILE/DATA/.HTPASSWD//Specify the location of the password file
Require Valid-user//specify that users who require authentication are all available users
</Directory>
</VirtualHost>
Next enter the command/usr/local/apache2.4/bin/htpasswd-c-m/data/.htpasswd Lys, enter, see,
Use-c to create a password file,-m to specify the password type MD5 encryption, Lys directly increase the user Lys. For a look at the file/data/.htpasswd, see,
You can see the file contains a bunch of garbled characters, the front is the user name Lys, followed by the password, this is because the M-set MD5 encryption password. Then create the user LYS2 for the second time, see,
This time the command does not have to add-c option, and then view the file/data/.htpasswd, you can see a row, the user name is Lys2.
The above is the process of creating a user, then, reload the configuration file,
Start testing, enter command curl-x127.0.0.1:80 111.com, carriage return, see,
Prompted a 401 error stating that the content of the access needs to be user authentication. Using the command curl-x127.0.0.1:80 111.com-i, enter, you can see the prompt www-authenticate:basic realm= "111.com user auth". We can also login on the browser, first add the website 111.com on the Windows hosts, see,
Save, then go to the browser, access 111.com, see,
As you can see, login requires a username and password. Then enter the user name Lys and password, see,
Click Login to enter,
The above is user authentication. So how do curl enter your username and password? Input command Curl-x127.0.0.1:80-ulys:ilovexm/[email protected] 111.com-i, enter, see,
This is entered, the format is-u user name: password, the status code is 200, is the normal state. If you enter the wrong password, it is the state,
The status code becomes 401 again.
There is another need for user authentication,
Assuming that the address of the background access is admin.php, you can do access authentication for this admin.php. This side uses the Filematch, meaning matches to the admin.php time, only then executes the following commands. Now, let's change it. config file, enter command vim/usr/local/apache2.4/conf/extra/httpd-vhosts.conf, carriage return, see,
Changed the contents of the red box, save and exit. Reload the configuration file,
Then also compile the 123.php file, enter the command vim/data/wwwroot/111.com/123.php, return, see,
Enter the content, save and exit. Echo is the meaning of the original output. Then do the test, enter the command!curl, return, see,
The first access to 111.com password is wrong can also enter, stating that no password is required to access. Then access 123.php, it began to error 401, this is because just for 123.php to do the user authentication restrictions. Need to enter user name and password, enter command curl-x127.0.0.1:80 111.com/123.php-ulys:ilovexm/[email protected]-I, enter, see,
Once you have entered your user name and password, you will be able to access it.
The above is user authentication, when some content does not want others to visit, it needs to add user authentication.
Apache user authentication