在我本機(jī)配置時間不長,不過花了好長的時間寫了份配置文檔,和大家分享一下,希望對大家有用
LINUX發(fā)行版本:Fedora 14 , Apache .2.2
安裝就不說了!依然采用rpm包安裝方式 ,下面進(jìn)入正題:
httpd.conf配置文件介紹
1、與Apache網(wǎng)絡(luò)和系統(tǒng)相關(guān)的選項(xiàng)
#使用ServerRoot參數(shù)設(shè)置Apache安裝目錄
# ServerRoot: The top of the directory tree under which the server's
# configuration, error, and log files are kept.
# you will save yourself a lot of trouble.
# Do NOT add a slash at the end of the directory path.
#
ServerRoot "/etc/httpd"
#使用Listen參數(shù)設(shè)置Apache監(jiān)聽端口,Apache默認(rèn)是80
Listen 80
#使用User參數(shù)設(shè)置Apache進(jìn)程的執(zhí)行者
User apache
#使用Group參數(shù)設(shè)置Apache進(jìn)程執(zhí)行者所屬的用戶組
Group apache
#使用ServerAdmin參數(shù)設(shè)置網(wǎng)站管理員的郵箱地址
2、與Apache文件和目錄權(quán)限相關(guān)選項(xiàng)
#使用DocumentRoot參數(shù)設(shè)置網(wǎng)站根目錄
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
DocumentRoot "/var/www/html"
#使用Directory段設(shè)置根目錄權(quán)限
Options FollowSymLinks
AllowOverride None
#使用Directory段設(shè)置/var/www/html目錄權(quán)限
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
?
#設(shè)置首頁為index.html
DirectoryIndex index.html index.html.var
#.ht后綴文件的訪問權(quán)限控制與上目錄的AllowOverride一起作用
# The following lines prevent .htaccess and .htpasswd files from being
# viewed by Web clients.
#
Order allow,deny
Deny from all
Satisfy All
?
3、與Apache日志相關(guān)的選項(xiàng)如下
#使用ErrorLog參數(shù)設(shè)置錯誤日志的位置
# ErrorLog: The location of the error log file.
# If you do not specify an ErrorLog directive within a
# container, error messages relating to that virtual host will be
# logged here. If you *do* define an error logfile for a
# container, that host's errors will be logged there and not here.
#
ErrorLog logs/error_log
#使用LogLevel參數(shù)設(shè)置錯誤日志的級別
# LogLevel: Control the number of messages logged to the error_log.
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
#
LogLevel warn
#使用LogFormat參數(shù)設(shè)置訪問日志的格式模板
# The following directives define some format nicknames for use with
# a CustomLog directive (see below).
#
LogFormat "%h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-Agent}i"" combined
LogFormat "%h %l %u %t "%r" %>s %b" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent
#使用CustomLog參數(shù)設(shè)置訪問日志的格式模板
# For a single logfile with access, agent, and referer information
# (Combined Logfile Format), use the following directive:
#
CustomLog logs/access_log combined
4、相關(guān)參數(shù)的解釋
1)ServerRoot參數(shù) 該參數(shù)用于指定Apache軟件安裝的目錄
2)Listen參數(shù) 用于指定Apache所監(jiān)聽的端口,默認(rèn)情況下Apache的監(jiān)聽端口為80.在服務(wù)器有多個IP地址的情況下,Listen參數(shù)還可以用于設(shè)置監(jiān)聽的Ip地址
3)User和Group參數(shù) 用于指定Apache進(jìn)程的執(zhí)行者和執(zhí)行者所屬的用戶組,如果要用UIG或者GID,必須在ID前面加上#號
4)ServerAdmin參數(shù) 該參數(shù)用于指定Web管理員的郵箱地址,這個地址會出現(xiàn)在系統(tǒng)連接出錯的時候,以便訪問者能夠及時通知WEB管理員。
5)DocumentRoot參數(shù) 該參數(shù)用于指定Web服務(wù)器上的文檔存放的位置,在未配置任何虛擬主機(jī)或虛擬目錄的情況下,用戶通過http訪問WEB服務(wù)器,所有的輸出資料文件均存放在這里。
6)ErrorLog 用于指定記錄,Apache運(yùn)行過程中所產(chǎn)生的錯誤信息的日志文件位置,方便系統(tǒng)管理員發(fā)現(xiàn)和觖決故障
5、符號鏈接和虛擬目錄
1)虛擬目錄是一種將根目錄以外的內(nèi)容加入到站點(diǎn)中的辦法。設(shè)置方法如下
#使用Alias參數(shù)設(shè)置虛擬目錄和實(shí)際目錄的對應(yīng)關(guān)系
Alias /lopn /var/www/lopn
#使用Directory段設(shè)置/var/www//lopn目錄的訪問權(quán)限
……………………………………
?
此時,重啟服務(wù)器,使用 域名或IP/lopn即可訪問
2)符號鏈接:其時符號鏈接所實(shí)現(xiàn)的功能和虛擬目錄是完全一樣的,只不過是實(shí)現(xiàn)機(jī)制不同而已!
還如上例:使用符號鏈接不需要修改配置文件,只需要在 根目錄下創(chuàng)建一個連接 使用如下指令
#ln -s /var/www/lopn lopn
此時即可通過 域名或IP/lopn即可訪問訪問到/var/www/lopn 下的內(nèi)容
6、個人空間
擁有帳號的本地帳號可以利用Apache發(fā)布自己的東西,假設(shè)有一用戶lopn,則其發(fā)布地址為http://主機(jī)/~lopn
下面我們開始配置
#
# UserDir is disabled by default since it can confirm the presence
# of a username on the system (depending on home directory
# permissions).
#
UserDir disabled root /禁止root用戶發(fā)布
#
# To enable requests to /~user/ to serve the user's public_html
# directory, remove the "UserDir disabled" line above, and uncomment
# the following line instead:
#
#UserDir public_html /去掉注釋符開啟功能,表示個人用戶目錄下的public_html 內(nèi)容發(fā)布
?
接下來要對目錄的權(quán)限進(jìn)行設(shè)置,如下,apache提供默認(rèn)設(shè)置,去掉#號即可,如下所示
# Control access to UserDir directories. The following is an example
# for a site where these directories are restricted to read-only.
#
AllowOverride FileInfo AuthConfig Limit
Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
Order allow,deny
Allow from all
?
Order deny,allow
Deny from all
?
?
#
這樣就配置好了個人空間。不過設(shè)置的時候注意權(quán)限的設(shè)置
7、Apache安全配置
Apache 提供了多種的安全控制手段,包括WEB訪問控制,用戶登錄密布認(rèn)證以及.htaccess文件等。
1)訪問控制
在配置文件中,Direcotry段用于設(shè)置與目錄相關(guān)的參數(shù)和指令,包括訪問控制和認(rèn)證
目錄相關(guān)的配置參數(shù)和指令
?
相關(guān)指令:1.Allow指令用于設(shè)置哪些客戶端可以方問Apache,格式如下
Allow from [All/全域名/部分域名/IP地址/網(wǎng)絡(luò)地址/CIDR地址]
2.Deny指令用于設(shè)置拒絕哪些客戶端訪問Apache,格式跟Allow一樣
3.Order指令用于指定執(zhí)行訪問規(guī)則的先后順序
Order Allow,Deny :先執(zhí)行充許訪問規(guī)則,再執(zhí)行拒絕訪問規(guī)則
Order Deny,Allow
2)用戶認(rèn)證
Apache的用戶認(rèn)證包括基本(Basic)認(rèn)證和摘要(Digest)認(rèn)證兩種。這里我們只探討一下基本認(rèn)證
基本認(rèn)證:當(dāng)Web瀏覽器請求經(jīng)此認(rèn)證模式保護(hù)的URL時,將會出現(xiàn)一個對話框,要求用記輸入用戶名和口令。如果正確,則返回頁面,否則返回401錯誤
要使用用戶認(rèn)證,首先要創(chuàng)建保存了用戶名和口令的認(rèn)證口令文件。可以用如下命令:
#htpasswd -c /etc/httpd/conf/users lopn *在/etc/httpd/conf目錄下創(chuàng)建一個名為users 的認(rèn)證口令文件,并加入一個名為lopn的用戶
#htpasswd /etc/httpd/conf/users xrp *表示加入一個xrp用戶
有了認(rèn)證口令文件,接下來我們需要更改配置文件
#
# Options Indexes FollowSymlinks
# AllowOverride None
#
# AuthType Basic *使用authtype參數(shù)設(shè)置認(rèn)證類型
# AuthName 領(lǐng)域名稱 *用天設(shè)置受保護(hù)領(lǐng)域的名稱,此處沒有限制,用戶可根喜好設(shè)置
# AuthUserFile /etc/httpd/conf/users *使用AuthUserFile參數(shù)設(shè)置認(rèn)證口令文件的位置
# Require user lopn *設(shè)置lopn用戶可以訪問
# Require valid-user *授權(quán)給認(rèn)證口令文件中的所有用戶 ,與上一個選一種即可
#
# Order ……
# ……
#
?
3)分布式配置文件.htaccess
.htaccess,該文件可以覆蓋httpd.conf文件中的配置,但是它只能設(shè)置對目錄的訪問控制和用戶認(rèn)證。.htaccess文件可以有多個,每個.htaccess文件的作用范圍僅限于該文件所存放的目錄以及該目錄下的所有子目錄。.htaccess所能實(shí)現(xiàn)的功能在配置文件中都能實(shí)現(xiàn),但是因?yàn)樵?htaccess修改配置后并不需要重啟服務(wù)就能生效,所以有時候是非常有用的1,操作如下
打開配置文件在,設(shè)置
#
# *允許.htaccess文件覆蓋httpd.conf文件中對該目錄的配置
# AllowOverride All
#
?
然后到指定的目錄,創(chuàng)建一個.htaccess文件,寫入配置,不用重啟就可以生效
8、虛擬主機(jī)(基于主機(jī)名)下面為配置文件中的說詳細(xì)說明,挺簡單,這里就不重復(fù)了
#NameVirtualHost *:80
#所有接口都接受該請求
# NOTE: NameVirtualHost cannot be used without a port specifier
# (e.g. :80) if mod_ssl is being used, due to the nature of the
# SSL protocol.
#
#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for requests without a known
# server name.
#
#
# ServerAdmin webmaster@dummy-host.example.com
# DocumentRoot /www/docs/dummy-host.example.com
# ServerName dummy-host.example.com
# ErrorLog logs/dummy-host.example.com-error_log
# CustomLog logs/dummy-host.example.com-access_log common
#
評論