AuthName "會員專區"
AuthType "Basic"
AuthUserFile "/var/tmp/xxx.pw" ----->把password放在網站外
require valid-user 到apache/bin目錄,建password檔 % ./htpasswd-c/var/tmp/xxx.pw username1----->第一次建檔要用參數"-c"
% ./htpasswd/var/tmp/xxx.pw username2
這樣就可以保護目錄內的內容,進入要用合法的用戶.
注:采用了Apache內附的模組。也可以采用在httpd.conf中加入:
options indexes followsymlinks
allowoverride authconfig
order allow,deny
allow from all
(4)Apache服務器訪問控制
我們就要看三個配置文件中的第三個文件了,即access.conf文件,它包含一些指令控制允許什么用戶訪問Apache目錄。應該把deny from all設為初始化指令,再使用allow from指令打開訪問權限。
<directory /usr/local/http/docs/private>
<limit>
order deny,allow
deny from all
allow from safechina.net
</limit>
</directory>
設置允許來自某個域、IP地址或者IP段的訪問。
(5)Apache服務器的密碼保護問題
我們再使用.htaccess文件把某個目錄的訪問權限賦予某個用戶。系統管理員需要在httpd.conf或者srm.conf文件中使用AccessFileName指令打開目錄的訪問控制。如:
AuthName PrivateFiles
AuthType Basic
AuthUserFile /path/to/httpd/users
require Phoenix
# htpasswd -c /path/to/httpd/users Phoenix
四,設置Apache服務器的WEB和文件服務器
我們在Apache服務器上存放WEB服務器的文件,供用戶訪問,并設置/home/ftp/pub目錄為文件存放區域,用http://download.XXXX.com/pub/來訪問。在防火墻上設置apache反向代理技術,由防火墻代理訪問。[page]
(1)Apache服務器的設置
apache服務器采用默認配置。主目錄為/home/httpd/html,主機域名為Phoenix.XXXX.com,且別名到www.XXXX.com中,并且設置srm.conf加一行別名定義如下:
Alias/pub/home/ftp/pub/
更改默認應用程序類型定義如下:
DefaultType application/octet-stream
最后在/etc/httpd/conf/access.conf中增加一項定義
Options Indexes
AllowOverride AuthConfig
order allow,deny
allow from all
注:Options Indexes允許在找不到index.html文件的情況下允許列出目錄/文件列表。AllowOverride AuthConfig允許做基本的用戶名和口令驗證。這樣的話,需要在/home/ftp/pub目錄下放入.htaccess,內容如下:
[root@shopu pub]# more .htaccess
AuthName Branch Office Public Software Download Area
AuthType Basic
AuthUserFile /etc/.usrpasswd
require valid-user
用# htpasswd -c /etc/.usrpasswd user1 分別創建不同的允許訪問/pub下文件服務的外部用戶名和口令。
(2)在防火墻上配置反向代理技術.
在/etc/httpd/conf/httpd.conf中加入 NameVirtualHost xxx.xxx.xxx.xxx
# xxx.xxx.xxx.xxx ----->是防火墻外部在互聯網上永久IP地址
servername www.XXXX.com
errorlog /var/log/httpd/error_log
transferlog /var/log/httpd/access_log
rewriteengine on
proxyrequests off
usecanonicalname off
rewriterule ^/(.*)$ http://xxx.xxx.xx.x/$1 Apache服務器的IP地址。
servername http://download.XXXX.com/pub/
errorlog /var/log/httpd/download/error_log
transferlog /var/log/httpd/download/access_log
rewriteengine on
proxyrequests off
usecanonicalname off
rewriterule^/(.*)$http://xxx.xxx.xx.x/$1 同上Apache服務器的IP地址。
設置防火墻上的DNS,讓download.XXXX.com和www.XXXX.com都指向防火墻的外部網地址xxx.xxx.xxx.xxx。用http://www.XXXX.com訪問主頁,用http://download.XXXX.com/pub/訪問公共文件的下載區。
注:還需要在apache服務器主機上建立目錄/var/log/httpd/download/,否則會出錯。另外,也可以設置防火墻主機上的/home/httpd/html/index.html的屬性為750來阻止訪問,這是防外部用戶能訪問到防火墻上的Apache服務器的http://www.XXXX.com中。
總結:Apache Server是一個非常優秀,非常棒的服務器,只要你正確配置和維護好Apache服務器,你就會感受到Apache Server 所帶來的好處。