web服務認證的實現

來源:互聯網
上載者:User

標籤:web服務   使用者   認證   

在登入網站時,我們可以實現基於使用者的認證,當然也可以基於單個使用者和組,配置大同小異,在此測試這一功能:

準備:

Centos6.3虛擬機器一台,IP地址:172.16.100.3,已配置好yum源並可以上網為了不影響效果,可以先關閉防火牆和SElinux

開始測試:

1.安裝必要軟體包

yum -y install httpd

2.簡單配置,並開啟此服務

a) [[email protected] ~]# vim /etc/httpd/conf/httpd.conf

搜尋:/#ServerName

添加ServerName localhost:80

b) [[email protected] ~]# cd /var/www/html/

在此處編輯一個名為index.html的網頁檔案,內容自訂

c) [[email protected] ~]# service httpd start

3.開啟瀏覽器,訪問172.16.100.3,可以訪問到自訂的網頁內容

4.編輯設定檔,加入相應配置

[[email protected] ~]# vim /etc/httpd/conf/httpd.conf

在<Directory "/var/www/html">段中修改和添加以下內容

    AllowOverride AuthConfig

    AuthType Basic

    AuthName "Restricted Site..."

    AuthUserFile "/etc/httpd/conf/htpasswd"

    Require valid-user

        5.建立兩個使用者,並在建立第一個使用者時建立認證使用者檔案

[[email protected] ~]# htpasswd -c -m /etc/httpd/conf/htpasswd hadoop

[[email protected] ~]# htpasswd  -m /etc/httpd/conf/htpasswd fsy

6.檢查設定檔是否有語法錯誤,若無誤,則重啟

[[email protected] ~]# httpd -t

[[email protected] ~]# service httpd restart

7.在瀏覽器測試即可

測試成功!

 

其他方式設定檔的修改:

基於單個使用者認證:

AllowOverride AuthConfig

AuthType Basic

AuthName "自訂"

AuthUserFile "/etc/httpd/conf/htpasswd"

Require user 使用者名稱

基於使用者組認證:

AllowOverride AuthConfig

AuthType Basic

AuthName "自訂"

AuthUserFile "/etc/httpd/conf/htpasswd"

AuthUserFile "/etc/httpd/conf/htgroups”

Require group 組名

 

編輯htgroups檔案,添加:

組名 使用者名稱(注意使用者名稱之間用空格隔開)

 

 

 

 

 

 


本文出自 “10917734” 部落格,請務必保留此出處http://10927734.blog.51cto.com/10917734/1844473

web服務認證的實現

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.