Apache authentication in Ubuntu

Source: Internet
Author: User
I. verification of username and password created based on htpasswd 1. create the user name and password file touch-f/tmp/shou /. passwdhtpasswd-B/tmp/shou /. passwdshoutest1234 ※htpasswd command usage reference: http://www.linuxidc.com/linux/2012-11/73915.htm2.

1. Authentication of username and password created based on htpasswd
1. Create a user name and password file

Touch-f/tmp/shou/. passwd
Htpasswd-B/tmp/shou/. passwd shou test1234

※Htpasswd command usage reference: http://www.linuxidc.com/Linux/2012-11/73915.htm
2. Configure the/etc/apache2/sites-available/default file

  1. Alias/test "/tmp/shou/test"
  2. Options Indexes FollowSymLinks MultiViews
  3. AllowOverride None
  4. Order allow, deny
  5. Allow from all
  6. AuthName "Authorization TEST (01 )"
  7. AuthType Basic
  8. AuthUserFile/tmp/shou/. passwd
  9. Require valid-user

Ii. Verification Based on MySQL database table information

1. Install the mod_auth_mysql module for MySQL verification.

Sudo apt-get install libapache2-mod-auth-mysql

2. Activate the mode_auth_mysql module.

Cd/etc/apache2/mod-enabled

Ln-s ../mod-available/auth_mysql.load

3. Create a database table and add data

  1. Create table tbl_user (
  2. Id integer not null primary key AUTO_INCREMENT,
  3. Username VARCHAR (128) not null,
  4. Password VARCHAR (128) not null,
  5. E-mail VARCHAR (128) NOT NULL
  6. );
  7. Insert into tbl_user (username, password, email) VALUES ('test1', 'pass1', 'test1 @ example.com ');
  8. Insert into tbl_user (username, password, email) VALUES ('test2', 'passs2 ', 'test2 @ example.com ');

4. Configure the/etc/apache2/sites-available/default file

  1. Alias/test1 "/tmp/shou/test1"
  2. Options Indexes FollowSymLinks MultiViews
  3. AllowOverride None
  4. Order allow, deny
  5. Allow from all
  6. AuthName "Authorization TEST (02 )"
  7. AuthType Basic
  8. Auth_MySQL On
  9. Auth_MySQL_Authoritative On
  10. Auth_MySQL_Host localhost
  11. Auth_MySQL_Username root
  12. Auth_MySQL_Password rootadmin
  13. Auth_MySQL_DB test
  14. Auth_MySQL_Password_Table tbl_user
  15. Auth_MySQL_Username_Field username
  16. Auth_MySQL_Password_Field password
  17. Auth_MySQL_Encryption_Types Plaintext
  18. Auth_MySQL_Empty_Passwords Off
  19. AuthBasicAuthoritative Off
  20. AuthUserFile/dev/null
  21. Require valid-user
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.