- 在 Web 虚擬主機上,設置需要使用者帳密才可登入的網站!
進階設定流程(一):
-
在 /etc/httpd/conf.d 目錄中,編寫之前的設定檔 vhosts.conf :
#vim /etc/httpd/conf.d/vhosts.conf <VirtualHost *:80> ServerName test1.example.com DocumentRoot /var/www/vhosts/test1 <Directory /var/www/vhosts/test1/sec> AuthType Basic AuthName "Restricted Area" AuthUserFile /var/www/vhosts/.htpasswd require valid-user </Directory> </VirtualHost>
-
新增 .htpasswd 檔案:
#cd /var/www/vhosts/.htpasswd #htpasswd -c .htpasswd peter (記得要輸入密碼) (再增加使用者時,不用 -c 參數) #htpasswd .htpasswd eric
-
修改 .htpasswd 權限:
#chmod 0411 .htpasswd
-
重新啟動 Apache :
#systemctl restart httpd
- http://www.seas.upenn.edu/cets/answers/auth-htpasswd.html