Detailed analysis: User authentication for Apache server implementation

  
                           The Apache server has a built-in user authentication mechanism, and you can control certain parts of the website to be authenticated by users as long as they are properly set up. As long as you follow me step by step, you should be able to easily implement user authentication. In preparation, you must have Apache installed. Step 1:
We create a test directory under /var/www (the root directory of apache's home page). Mkdir /var/www/test Step 2:
Then we edit httpd.conf add
Alias ​​/test"/var/www/test"<Directory "/var/www/test"> ;Options Indexes MultiViewsAllowOverride AuthConfig # indicates authenticated Order allow, denyAllow from all</Directory> #AllowOverride AuthConfig indicates that authentication is the key setting Step 3:
Created in /var/www/test .htaccess file vi /var/www/test/.htaccess AuthName "frank share web" AuthType Basic AuthUserFile /var/www/test/.htpasswd require valid-user #AuthName Description, just write #AuthUserFile /var/www/test/.htpasswd #require valid-user or require user frank limit is all legitimate users or specified users # password file recommended to use .htpasswd, because apache default system for the beginning of the ".ht" file does not allow external reading by default, the safety factor will be high A little. Step 4:
Is to create the apache verification user htpasswd -c /var/www/test/.htpasswd frank #The first time you create a user you need to use the -c parameter to add users for the second time, you don't need - c parameters If you want to change the password, you can htpasswd -m .htpasswd frank Step 5:
ok, restart the apache service, then visit http://your website address /test If it goes well, it should be able To see a pop-up window for user authentication, just fill in the username and password created in step 4. For the performance of the server, it is generally not recommended to use AllowOverride AuthConfig or AllowOverride ALL, because this will cause the server to constantly search for .htaccess, which affects the performance of the server. Generally, we may need to verify some background management interface or other special directories. demand.
Copyright © Windows knowledge All Rights Reserved