LAMP-Apache使用者認證

來源:互聯網
上載者:User

標籤:apache

   在某些情境下,網站頁面的內容需要特殊授權使用者才能查看。要實現這個功能,需要在Apache上做設定認證使用者。


1、編輯虛擬機器主機配置

[[email protected] ~]# vi /usr/local/apache2.4/conf/extra/httpd-vhosts.conf<VirtualHost *:80>    DocumentRoot "/data/www/abc.com"    ServerName abc.com    <Directory /data/www/abc.com>             ##指定認證的目錄        AllowOverride AuthConfig              ##開啟認證開關        AuthName "abc.com user auth"          ##定義認證的名字        AuthType Basic                        ##指定認證的類型        AuthUserFile /data/.htpasswd          ##指定密碼檔案所在的位置        require valid-user                    ##指定需要認證的使用者    </Directory></VirtualHost>


2、增加使用者

[[email protected] ~]# /usr/local/apache2.4/bin/htpasswd -c -m /data/.htpasswd juispanNew password:                                  ##“-c”=create “-m”=md5Re-type new password:                          ##“/data/.htpasswd”=密碼存放路徑Adding password for user juispan[[email protected] ~]# cat /data/.htpasswd juispan:$apr1$5UVKQ8Ux$8tkRftVA0ueh7qtD6tzlz1


3、檢查重新載入

[[email protected] ~]# /usr/local/apache2.4/bin/apachectl -tSyntax OK[[email protected] ~]# /usr/local/apache2.4/bin/apachectl graceful


4、測實驗證

本機驗證:

[[email protected] ~]# curl -x127.0.0.1:80 abc.com<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"><html><head><title>401 Unauthorized</title>                      ##401 未認證</head><body><h1>Unauthorized</h1><p>This server could not verify that youare authorized to access the documentrequested.  Either you supplied the wrongcredentials (e.g., bad password), or yourbrowser doesn‘t understand how to supplythe credentials required.</p></body></html>[[email protected] ~]# curl -x127.0.0.1:80 -ujuispan:hao123.com abc.comabc.com

遠端驗證:

650) this.width=650;" src="https://s2.51cto.com/wyfs02/M00/9D/78/wKioL1mAgwnDUNsGAABAFbCNgGQ191.png-wh_500x0-wm_3-wmp_4-s_1465511015.png" title="1.png" alt="wKioL1mAgwnDUNsGAABAFbCNgGQ191.png-wh_50" />

    輸入正確的使用者名稱口令後即可顯示網頁內容。


如果針對的不是整個目錄,而是單個網頁,可以使用FilesMatch替換Directory,如<FilesMatch 1.php> 。

▎參考配置:

<VirtualHost *:80>    DocumentRoot "/data/www/abc.com"    ServerName www.abc.com    <FilesMatch 1.php>        AllowOverride AuthConfig        AuthName "abc.com user auth"        AuthType Basic        AuthUserFile /data/.htpasswd        require valid-user    </FilesMatch></VirtualHost>


本文出自 “Gorilla Grodd” 部落格,請務必保留此出處http://juispan.blog.51cto.com/943137/1952793

LAMP-Apache使用者認證

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.