windows中安裝Apache http server(httpd-2.4.58-win64-VS17)
1、下載windows版本的的httpd,
https://httpd.apache.org/docs/current/platform/windows.html#down
這里選擇的是Apache Lounge編譯的版本
https://www.apachelounge.com/download/
2、解壓到指定目錄,這里解壓到D盤根目錄,得到D:\Apache24
3、修改配置文件http.conf
# 服務的根目錄(根據(jù)實際情況修改)
Define SRVROOT "D:/Apache24"
# 需要監(jiān)聽的端口(根據(jù)需要修改)
Listen 80
4、修改之后,檢測配置文件是否有語法錯誤
# 檢測配置文件語法是否有錯誤
httpd.exe -t
語法OK,至于ServerName的問題可以暫時不處理。
6、注冊服務,根據(jù)命令提示注冊windows服務
# 注冊服務,默認服務名為Apache2.4
httpd.exe -k install
# 卸載服務,默認卸載服務名為Apache2.4
httpd.exe -k uninstall
# 注冊服務,指定服務名
httpd.exe -k install -n Httpd2.4
# 卸載服務,指定服務名
httpd.exe -k uninstall -n Httpd2.4
7、啟動服務
使用命令啟動服務,或者打開服務管理窗口啟動服務
# 使用net命令啟動服務
net start Apache2.4
8、使用瀏覽器,查看
It works!
表示服務安裝、運行正常。
9、部署前端項目、設置vhosts,編輯conf\extra\httpd-vhosts.conf。根據(jù)項目需要設置自己的VirtualHost。
<VirtualHost *:80>
DocumentRoot D:/Apache24/dist
ServerName 192.168.0.44
<Directory D:/Apache24/dist>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.html [L]
SetOutputFilter DEFLATE
Options FollowSymLinks
AllowOverride All
Require all granted
DirectoryIndex index.php index.html index.htm default.php default.html default.htm
</Directory>
ProxyRequests off
ProxyPass /prod-api http://192.168.0.44:8097
ProxyPassReverse /prod-api http://192.168.0.44:8097
</VirtualHost>
# 在主配置文件httpd.conf中把引入httpd-vhosts.conf文件的注釋去掉
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
10、處理異常問題
此時重啟服務,發(fā)現(xiàn)服務是無法啟動的,我們再使用httpd.exe -t,檢測一下配置文件,根據(jù)提示解決問題
①RewriteEngine on,開啟了重寫引擎,需要引入相關模塊
在主配置文件httpd.conf中搜索關鍵詞,把重寫模塊引入進來
# 把注釋去掉
LoadModule rewrite_module modules/mod_rewrite.so
②vhost中使用了反向代理,需要把代理模塊引入進來
在主配置文件httpd.conf中引入代理請求模塊
# 把注釋去掉
LoadModule proxy_module modules/mod_proxy.so
# 引入上述兩個模塊后,服務可以正常啟動了,但是仍不能完成代理請求工作,項目是http請求,所以還需要把http這個子模塊引入進來
LoadModule proxy_http_module modules/mod_proxy_http.so
11、訪問項目,查看運行情況。
12、隱藏Httpd版本信息和操作系統(tǒng)信息
可以在\conf\extra中新建一個httpd-servertokens.conf配置文件,從httpd-default.conf中把ServerTokens的信息復制過來。
并修改為ServerTokens Prod。之后在主配置文件中引入該文件,并重啟服務。文章來源:http://www.zghlxwxcb.cn/news/detail-808719.html
#
# ServerTokens
# This directive configures what you return as the Server HTTP response
# Header. The default is 'Full' which sends information about the OS-Type
# and compiled in modules.
# Set to one of: Full | OS | Minor | Minimal | Major | Prod
# where Full conveys the most information, and Prod the least.
#
ServerTokens Prod
# ServerTokens
Include conf/extra/httpd-servertokens.conf
小尾巴~~
只要有積累,就會有進步文章來源地址http://www.zghlxwxcb.cn/news/detail-808719.html
到了這里,關于window中安裝Apache http server(httpd-2.4.58-win64-VS17)的文章就介紹完了。如果您還想了解更多內容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!