標籤: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 使用者認證