Windows Apache2.4 VC9(ApacheHaus)詳細(xì)安裝配置教程
1,Apache下載

選擇一個(gè)版本,點(diǎn)擊Download

點(diǎn)擊File For Microsoft Windows

由于A(yíng)pache HTTP Server官方不提供二進(jìn)制(可執(zhí)行)的發(fā)行版,所以我們選擇一些貢獻(xiàn)者編譯完成的版本,我們選擇第一個(gè)ApacheHaus
點(diǎn)擊ApacheHaus,進(jìn)入下載頁(yè)

選擇其中一個(gè)版本,如果你的Windows還沒(méi)安裝對(duì)應(yīng)的VC環(huán)境的話(huà),選擇對(duì)應(yīng)的VCRedistribute版本下載安裝。我選擇Apache 2.4VC9版,因?yàn)槲业碾娔X中已經(jīng)安裝了VC9的環(huán)境。
點(diǎn)擊JumpLinks下第一行的某一個(gè)版本,下載對(duì)應(yīng)壓縮包。
2,配置Apache之一--httpd.conf
解壓后進(jìn)入里面Apache22(最后兩位數(shù)字可能不同)文件夾,使用文本編輯器(推薦ultraedit)打開(kāi)conf文件夾中的httpd.conf配置文件
找到ServerRoot選項(xiàng),設(shè)置Apache目錄,大約在35行左右,將其改成你的Apache程序的文件夾,例:
ServerRoot "C:/Users/myPC/Downloads/httpd-2.2.31-x86-r3/Apache22"
找到Listen選項(xiàng),設(shè)置端口,大約46行,一般不修改,使用默認(rèn)80,在開(kāi)啟服務(wù)器前請(qǐng)保證80端口未被占用
找到DocumentRoot選項(xiàng),修改服務(wù)器根目錄,例:
DocumentRoot "F:/"
請(qǐng)保證此目錄存在,否則服務(wù)器無(wú)法正常啟動(dòng)
修改Directory,保證其與服務(wù)器根目錄相同,只修改下面的第一行中引號(hào)部分
<Directory "F:/"> # # Possible values for the Options directive are "None", "All", # or any combination of: # Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews # # Note that "MultiViews" must be named *explicitly* --- "Options All" # doesn't give it to you. # # The Options directive is both complicated and important. Please see # http://httpd.apache.org/docs/2.2/mod/core.html#options # for more information. # Options Indexes FollowSymLinks # # AllowOverride controls what directives may be placed in .htaccess files. # It can be "All", "None", or any combination of the keywords: # Options FileInfo AuthConfig Limit # AllowOverride None # # Controls who can get stuff from this server. # Order allow,deny Allow from all </Directory>
找到ScriptAlias選項(xiàng),設(shè)置服務(wù)器腳本目錄,大約326行,一般將其設(shè)置為Apache目錄下的cgi-bin文件夾
ScriptAlias /cgi-bin/ "C:/Users/myPC/Downloads/httpd-2.2.31-x86-r3/Apache22/cgi-bin"
找到隨后的Directory選項(xiàng),設(shè)置腳本目錄,大約342行,需要將其設(shè)置為和前面的ScriptAlias目錄相同
<Directory "C:/Users/myPC/Downloads/httpd-2.2.31-x86-r3/Apache22/cgi-bin"> AllowOverride None Options None Order allow,deny Allow from all </Directory>
3,配置Apache之二--ssl配置
如果你這使啟動(dòng)服務(wù),一般會(huì)出現(xiàn)下面的消息對(duì)話(huà)框:

提示
Windows不能在本地計(jì)算機(jī)啟動(dòng)Apache2.2。有關(guān)更多信息,查閱系統(tǒng)日志文件。如果這是非Microsoft服務(wù),請(qǐng)與廠(chǎng)商聯(lián)系,并參考特定服務(wù)器錯(cuò)誤代碼1。
確定此問(wèn)題的原因:
右鍵 計(jì)算機(jī),點(diǎn)擊管理->Windows日志->應(yīng)用程序,顯示如下


這是由于SSL配置不正確所產(chǎn)生的,下面說(shuō)一下解決辦法。
打開(kāi)Apache程序目錄下的conf/extra/httpd-ahssl.conf文件,配置VirtualHost選項(xiàng),有三處名為VirtualHost的選項(xiàng),均需修改。
第一個(gè)在107行左右。
在110行左右,將其中的SSLCertificateFile改為:Apache所在目錄/conf/ssl/server.crt
在111行左右,將SSLCertificateKeyFile改為:Apache所在目錄/conf/ssl/server.key
在112行左右,將DocumentRoot改為你的服務(wù)器根目錄
在126行左右,將CustomLog改為:Apache所在目錄/logs/ssl_request.log,這個(gè)不改的話(huà)也會(huì)錯(cuò)。一般會(huì)出現(xiàn)如下錯(cuò)誤:

Apache2.2服務(wù)由于下列服務(wù)特定錯(cuò)誤而終止:函數(shù)不正確。
改成的效果:
<VirtualHost _default_:443>
SSLEngine on
ServerName localhost:443
SSLCertificateFile C:/Users/myPC/Downloads/httpd-2.2.31-x86-r3/Apache22/conf/ssl/server.crt
SSLCertificateKeyFile C:/Users/myPC/Downloads/httpd-2.2.31-x86-r3/Apache22/conf/ssl/server.key
DocumentRoot F:/
# openssl req -new > server.csr
# openssl rsa -in privkey.pem -out server.key
# openssl x509 -in server.csr -out server.crt -req -signkey server.key -days 2048
<FilesMatch "\.(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
<Directory "/Apache22/cgi-bin">
SSLOptions +StdEnvVars
</Directory>
BrowserMatch "MSIE [2-5]" \
nokeepalive ssl-unclean-shutdown \
downgrade-1.0 force-response-1.0
CustomLog "C:/Users/myPC/Downloads/httpd-2.2.31-x86-r3/Apache22/logs/ssl_request.log" \
"%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
</virtualhost>
主要改上文四處地方
在130行和152行還有另外兩個(gè)VirtualHost,均需修改上述的四個(gè)選項(xiàng)
例:
130行
<VirtualHost *:443>
SSLEngine on
ServerName serverone.tld:443
SSLCertificateFile C:/Users/myPC/Downloads/httpd-2.2.31-x86-r3/Apache22/conf/ssl/serverone.crt
SSLCertificateKeyFile C:/Users/myPC/Downloads/httpd-2.2.31-x86-r3/Apache22/conf/ssl/serverone.key
DocumentRoot F:/
# openssl req -new > serverone.csr
# openssl rsa -in privkey.pem -out serverone.key
# openssl x509 -in serverone.csr -out serverone.crt -req -signkey serverone.key -days 2048
<FilesMatch "\.(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
<Directory "/Apache22/cgi-bin">
SSLOptions +StdEnvVars
</Directory>
BrowserMatch "MSIE [2-5]" \
nokeepalive ssl-unclean-shutdown \
downgrade-1.0 force-response-1.0
CustomLog "C:/Users/myPC/Downloads/httpd-2.2.31-x86-r3/Apache22/logs/ssl_request.log" \
"%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b" env=HTTPS
</virtualhost>
第152行
<VirtualHost *:443>
SSLEngine on
ServerName servertwo.tld:443
SSLCertificateFile C:/Users/myPC/Downloads/httpd-2.2.31-x86-r3/Apache22/conf/ssl/servertwo.crt
SSLCertificateKeyFile C:/Users/myPC/Downloads/httpd-2.2.31-x86-r3/Apache22/conf/ssl/servertwo.key
DocumentRoot F:/
# openssl req -new > servertwo.csr
# openssl rsa -in privkey.pem -out servertwo.key
# openssl x509 -in servertwo.csr -out servertwo.crt -req -signkey servertwo.key -days 2048
<FilesMatch "\.(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
<Directory "/Apache22/cgi-bin">
SSLOptions +StdEnvVars
</Directory>
BrowserMatch "MSIE [2-5]" \
nokeepalive ssl-unclean-shutdown \
downgrade-1.0 force-response-1.0
CustomLog "C:/Users/myPC/Downloads/httpd-2.2.31-x86-r3/Apache22/ssl_request.log" \
"%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
</virtualhost>
上述的兩個(gè)VirtualHost均需修改四處
這樣,Apache就算配置完了,如果還有問(wèn)題,可能還需配置./conf/extra/httpd-ssl.conf,配置方法和配置VirtualHost的相似
4,啟動(dòng)Apache HTTP Server
使用Windows命令行以管理員身份進(jìn)入Apache程序的文件夾下的bin文件夾,輸入httpd -k install,完成Apache服務(wù)的安裝。
然后雙擊bin目錄下的ApacheMonitor.exe,點(diǎn)擊右邊的start啟動(dòng)服務(wù)器,如果正常,如下圖:

測(cè)試一下:

5,其它
卸載Apache HTTP Server:
管理員身份進(jìn)入bin目錄,使用httpd -k uninstall 移除服務(wù)
使用httpd -w -n "Apache2" -k start命令啟動(dòng)服務(wù)器 可以顯示啟動(dòng)過(guò)程中的日志,便于分析錯(cuò)誤。
相關(guān)文章
Ubuntu下安裝nvidia顯卡驅(qū)動(dòng)(安裝方式簡(jiǎn)單)
這篇文章主要介紹了Ubuntu下安裝nvidia顯卡驅(qū)動(dòng),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-05-05
Linux下如何檢查網(wǎng)卡bonding狀態(tài)和切換主備網(wǎng)卡
這篇文章主要介紹了Linux下如何檢查網(wǎng)卡bonding狀態(tài)和切換主備網(wǎng)卡問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-11-11
Canonical通過(guò)Flutter啟用Linux桌面應(yīng)用程序(推薦)
這篇文章主要介紹了Canonical通過(guò)Flutter啟用Linux桌面應(yīng)用程序,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-07-07
ubuntu系統(tǒng)修改時(shí)區(qū)和時(shí)間的方法
今天小編就為大家分享一篇關(guān)于ubuntu系統(tǒng)修改時(shí)區(qū)和時(shí)間的方法,小編覺(jué)得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來(lái)看看吧2019-03-03
centos8 使用yum 安裝 mongodb 4.2的方法
這篇文章主要介紹了centos8 使用yum 安裝 mongodb 4.2的方法,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-10-10
linux中g(shù)rep命令使用實(shí)戰(zhàn)詳解
這篇文章主要介紹了linux中g(shù)rep命令使用實(shí)戰(zhàn)詳解的相關(guān)資料,需要的朋友可以參考下2023-02-02
windows下實(shí)現(xiàn)定時(shí)重啟Apache與MySQL方法
有時(shí)候?yàn)榱朔?wù)器具有更好的效率,可以定時(shí)重啟apache服務(wù)等。讓網(wǎng)站運(yùn)行的效果更快。2010-09-09

