Windows 下搭建 Apache Http Server 文件系統(詳細)
一、下載Apache Http Sever 2.4
(1)https://httpd.apache.org/download.cgi#apache24
(2)在 Apache 2.4 server binaries 欄選擇 合適版本進行下載
二、安裝與配置Apache Http Sever 2.4
(1)解壓壓縮包,得到下圖所示的文件。一個是安裝說明readme_first.html,一個是Apache24的文件夾。
(2)修改配置F:\Apache24\conf\httpd.conf
指定 Apache24根目錄為F:\Apache24
修改監聽端口 為8080,默認是80端口
修改文件存放路徑 ,默認就是 F:\Apache24\htdocs 目錄
Define SRVROOT "F:\Apache24" ServerRoot "${SRVROOT}"
Listen 8080
//這里可以修改默認文件存放路徑
DocumentRoot "${SRVROOT}/htdocs"
(3)執行安裝命令
httpd.exe?-k?install?-n?"Apache24"
三 、啟動Apache Http Server
方式一:通過命令行啟動
通過如下命令可以開啟和關閉Apache24服務:
httpd.exe?-k?start?-n?"Apache24" httpd.exe?-k?stop?-n?"Apache24"
附: 重啟和卸載http的命令
httpd.exe?-k?restart?-n?"Apache24" httpd.exe?-k?uninstall?-n?"Apache24"
方式二:通過ApacheMonitor啟動
雙擊/bin目錄下的ApacheMonitor.exe,在筆者的電腦上,這個程序會最小化到托盤:
雙擊圖標,即可圖形化的方式運行:
選中Apache24,可以start(啟動)它,啟動成功后,最小化到托盤的圖標會變成綠色的三角形,說明已經成功啟動。
方式三:直接點擊services.msc服務中的Apache24,啟動或者停止服務
服務啟動以后,可以在瀏覽器中輸入http://localhost:8080,就可以查看到目錄F:\Apache24\htdocs下的index.html文件。
在F:\Apache24\htdocs目錄新建一個file 文件夾,然后放置一些文件,再次訪問[http://localhost:8080/file 也是沒問題的。
四、安裝啟動過程中可能出現的錯誤
(1)安裝報錯
Errors reported here must be corrected before the service can be started.(OS 10048)通常每個套接字地址(協議/網絡地址/端口)只允許使用一次。 : AH00072: make_sock: could not bind to address [::]:443(OS 10048)通常每個套接字地址(協議/網絡地址/端口)只允許使用一次。 : AH00072: make_sock: could not bind to address 0.0.0.0:443
說明443端口已經被占用
可用如下命令查看哪些 服務占用 了443端口
netstat?-ano????? netstat?-ano|findstr?:443
可以停掉 占用443端口的服務,或者修改F:\Apache24\conf\extra\httpd-ahssl.conf
打開F:\Apache24\conf目錄下的httpd.conf,搜索ssl ,找到如下文字
#?Secure?(SSL/TLS)?connections #?Note:?The?following?must?must?be?present?to?support #???????starting?without?SSL?on?platforms?with?no?/dev/random?equivalent #???????but?a?statically?compiled-in?mod_ssl. #
發現 ssl 443 端口 是配置 在 F:\Apache24\conf\extra\httpd-ahssl.conf 這個文件里面
將其中的443改成其他端口,如1443
第一處(Line 18) 、第二處(Line 134,136)、第三處(Line 150,152) 、 第四處(Line 165,167)的 443 全部改成 1443,
在用 管理員 再次執行 安裝命令httpd.exe -k install -n "Apache24" 即可。
(2)解決啟動Apache http server時報錯(1053)
安裝好http server后,一直無法啟動服務,使用上述的方式一和方式二均未成功,而且不知道錯誤在哪里。使用方式三啟動服務時,系統報錯1053:服務沒有及時響應啟動或控制請求。
后來參考這個鏈接https://www.apachelounge.com/viewtopic.php?p=34728 ,估計自己也是因為沒有安裝最新的vc_redist.x64.exe。
到windows官網下載該程序,完成安裝后,服務能正常啟動了。
vc_redist.x64.exe的-: https://www.microsoft.com/en-us/download/details.aspx?id=48145
五、設置 basic 用戶認證
進入 F:\Apache24下的bin 目錄
執行以下命令 創建 .htpasswd 文件,并添加 admin 用戶 admin1用戶
.\htpasswd.exe -bc F:\Apache24\conf.htpasswd admin 123456
.\htpasswd.exe -b F:\Apache24\conf.htpasswd admin1 123456
注意 : -c 參數 表示創建文件,-b表示將 用戶信息追加到已經存在的文件中
(1)方式一,
直接修改 F:\Apache24\conf\httpd.conf 的
#
# 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.4/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
AllowOverride AuthConfig
AuthType basic
AuthName "allinone file server..."
AuthUserFile F:/Apache24/conf/.htpasswd
Require valid-user
#
# Controls who can get stuff from this server.
#
#Require all granted
重啟apache http server
(2)方式二
在 F:\Apache24\htdocs 目錄下創建.htaccess文件,并添加如下內容
AuthName?"allinone?file?server..." AuthType?basic AuthUserFile?F:/Apache24/conf/.htpasswd require?valid-user
重啟apache http server
再次訪問 localhost:8080,彈出 用戶驗證窗口
Windows Server
版權聲明:本文內容由網絡用戶投稿,版權歸原作者所有,本站不擁有其著作權,亦不承擔相應法律責任。如果您發現本站中有涉嫌抄襲或描述失實的內容,請聯系我們jiasou666@gmail.com 處理,核實后本網站將在24小時內刪除侵權內容。