LAMP 之 Apache 使用者認證

來源:互聯網
上載者:User

標籤:discuz 之apache 驗證

第一步登陸上Discuz 之後,我們用做一個Apache 的使用者認證

650) this.width=650;" src="http://s2.51cto.com/wyfs02/M02/88/17/wKiom1fpMpqhak23AAI-2Un0e4U819.jpg-wh_500x0-wm_3-wmp_4-s_3642110675.jpg" title="dis11.jpg" alt="wKiom1fpMpqhak23AAI-2Un0e4U819.jpg-wh_50" />

此網站有一個目錄,上面有一些重要的檔案,不需要其他人看見,只有管理員可以看,但是還要方便在網站上展示。

樣本:

[[email protected] ~]# cd /data/www/

[[email protected] www]# mkdir abc

[[email protected] www]# cd abc/

[[email protected] abc]# cp /etc/passwd ./12.txt

在網頁上訪問此目錄

650) this.width=650;" src="http://s1.51cto.com/wyfs02/M02/88/14/wKioL1fpN62y7EFBAAIoWJVq7Xk307.jpg-wh_500x0-wm_3-wmp_4-s_2995144546.jpg" title="dis12.jpg" alt="wKioL1fpN62y7EFBAAIoWJVq7Xk307.jpg-wh_50" />


假設此檔案很重要,必須要在web 上訪問,但是還不想讓別人訪問,此時就需要做一個使用者認證。

編譯虛擬機器主機檔案

[[email protected] abc]# vim /usr/local/apache2/conf/extra/httpd-vhosts.conf 

增加內容

    <Directory /data/www/abc>  # 指定路徑

        AllowOverride AuthConfig

        AuthName "aaaa"     更改此處

        AuthType Basic

        AuthUserFile /data/.htpasswd  #這個檔案是必須存在的,是存放使用者名稱和密碼的。 

        require valid-user  # 這一項重要,不要忘記,沒有配置會驗證失敗,不能訪問

</Directory> 

 則會彈框會提示 aaaa

每次都輸入Apache 的絕對路徑太長的,我們手動添加一個路徑設定

vim /etc/profile.d/path.sh

#!/bin/bash

export PATH=$PATH:/usr/local/mysql/bin:/usr/local/apache2/bin

[[email protected] abc]# source /etc/profile.d/path.sh 

接下來建立使用者和密碼檔案

[[email protected] abc]# htpasswd -c /data/.htpasswd user1

New password: 此處輸入密碼

Re-type new password: 

Adding password for user user1  建立使用者成功。

建立第二個使用者,注意區分文法

[[email protected] abc]# htpasswd /data/.htpasswd user2  不用加C ,加C 會覆蓋前面的檔案

New password: 

Re-type new password: 

Adding password for user user2

查看檔案

[[email protected] abc]# !cat

cat /data/.htpasswd 

user1:NQCeGBRtW6PiU

user2:BKvH5X80FImm.

檢查apache 設定檔有沒有問題

[[email protected] abc]# apachectl -t

Syntax OK

[[email protected] abc]# apachectl restart

再次重新訪問 www.test.com/abc/12.txt. 輸入剛才定義的使用者名稱和密碼可以正常顯示剛才的檔案

650) this.width=650;" src="http://s3.51cto.com/wyfs02/M01/88/14/wKioL1fpPqnAuFGrAAFHcySlRak382.jpg-wh_500x0-wm_3-wmp_4-s_1783418448.jpg" title="dis13.jpg" alt="wKioL1fpPqnAuFGrAAFHcySlRak382.jpg-wh_50" />

本文出自 “CBO#Boy_Linux之路” 部落格,請務必保留此出處http://20151213start.blog.51cto.com/9472657/1856799

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.