Thiết lập Password Authentication Apache trên Ubuntu 14.04

Cài Đặt Apache Utilites

  • sudo apt-get update
  • sudo apt-get install apache2 apache2-utils

Tạo Password File

  • sudo htpasswd -c /etc/apache2/.htpasswd <username>

Selection_009– Kiểm tra file .htpasswd

  • sudo vi /etc/apache2/.htpasswd

Selection_010 Selection_011

Cấu hình Apache Password Authentication

1. Dùng Virtual Host

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /home/truongnguyen/www/lara5111
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    <Directory /home/truongnguyen/www/lara5111>
         Options Indexes FollowSymLinks MultiViews
         AllowOverride All
         Order allow,deny
         allow from all
         AuthType Basic
         AuthName "Login"
         AuthUserFile /etc/apache2/.htpasswd
         Require valid-user

- Restart apche
- sudo service apache2 restart

2. Dùng .htaccess

Thêm 4 dòng code vào đầu file .htaccess

AuthUserFile /etc/apache2/.htpasswd
AuthType Basic
AuthName "Login"
Require valid-user
Done ^_^

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s