2007年12月24日 星期一

Service: Apache - User's Personal web site


基礎需求:
帳號設定篇,套件安裝篇,apache基本操作篇

環境設定:
rpm -q httpd mod_ssl
若無相關套件請參照套件安裝篇: Utility: rpm + yum
service iptables stop

1. 在網頁空間設定上首要注意資料夾權限與SElinux設定在本次實做中以分享/home/alex為例:

useradd alex

cd /home/alex

mkdir public_html

chmod 701 /home/alex

chmod 701 /home/alex/public_html

cd /home/alex/public_html

cat >> index.html
<b> Welcome2Alex's Web Site</b>
ctrl-D

restorecon -R -v public_html

2.修改 /etc/httpd/conf/httpd.conf 約在338行開始處尋找以下字串

#
# UserDir: The name of the directory that is appended onto a user's home
# directory if a ~user request is received.
#
# The path to the end user account 'public_html' directory must be
# accessible to the webserver userid. This usually means that ~userid
# must have permissions of 711, ~userid/public_html must have permissions
# of 755, and documents contained therein must be world-readable.
# Otherwise, the client will only receive a "403 Forbidden" message.
#
# See also: http://httpd.apache.org/docs/misc/FAQ.html#forbidden
#
<IfModule mod_userdir.c>
#
# UserDir is disabled by default since it can confirm the presence
# of a username on the system (depending on home directory
# permissions).
#
#UserDir disable

#
# To enable requests to /~user/ to serve the user's public_html
# directory, remove the "UserDir disable" line above, and uncomment
# the following line instead:
#
UserDir public_html

</IfModule>

#
# Control access to UserDir directories. The following is an example
# for a site where these directories are restricted to read-only.
#
<Directory /home/*/public_html>
AllowOverride FileInfo AuthConfig Limit
Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
# AllowOverride AuthConfig
# AuthType Basic
# AuthName "Passwd Protected Test"
# AuthUserFile /etc/httpd/.htpasswd
# require valid-user

# <Limit GET POST OPTIONS>
# Order allow,deny
# Allow from all
# </Limit>
# <LimitExcept GET POST OPTIONS>
# Order deny,allow
# Deny from all
# </LimitExcept>
</Directory>

設定值解說
  • 將UserDir disable設定改為 #UserDir disable並改為UserDir public_html,便是將預設的個人網頁空間設定為/home/*/public/html
  • 設定密碼保護
# AllowOverride AuthConfig
# AuthType Basic
# AuthName "Passwd Protected Test"
# AuthUserFile /etc/httpd/.htpasswd
# require valid-user

將以上字串的#字號拿掉後在加入以下的指令:

htpasswd -cm /etc/httpd/.htpasswd alex

chmod 640 /etc/httpd/.htpasswd

在進入網頁時便會要求輸入帳號密碼,即User based的保護機制,如下圖所示:

links http://server1/~alex

3. 檢查設定檔與執行

請執行以下指令

httpd -t

apachectl restart

4. 測試網頁

links http://ip-web service host/~alex

沒有留言: