正文
window下Apache-http-server(httpd-2.4.12)安装与配置
小程序:扫一扫查出行
【扫一扫了解最新限行尾号】
复制小程序
【扫一扫了解最新限行尾号】
复制小程序
由于Apache官网改变策略(2015年1月左右),官网不再提供Apache-http-server的windows的编译版本,但是提供了几个第三方的版本
http://httpd.apache.org/docs/current/platform/windows.html#down
分别是ApacheHaus、Apache Lounge、BitNami WAMP Stack、WampServer、XAMPP
笔者进的是ApacheHaus下载Apache 2.4.x VC9 64位版本
建议下载httpd-2.4.12-x64-r2.zip、httpd-2.4.12-x86-r2.zip
然后下载对应的VC9(VC2008)运行库
32位
http://www.microsoft.com/downloads/en/details.aspx?FamilyID=A5C84275-3B97-4AB7-A40D-3802B2AF5FC2
64位
http://www.microsoft.com/downloads/en/details.aspx?FamilyID=BA9257CA-337F-4B40-8C14-157CFDFFEE4E
安装好VC9运行库之后,将httpd-2.4.12-x64-r2.zip里面的Apache24文件夹放到D盘根目录(注意:必须放到根目录,其他目录启动和加载模块会出错)
然后打开命令行,切换到bin目录,运行httpd.exe
C:\Users\test>D: D:\>cd Apache24 D:\Apache24>cd bin D:\Apache24\bin>httpd.exe
(OS )通常每个套接字地址(协议/网络地址/端口)只允许使用一次。 : AH00072: mak
e_sock: could not bind to address [::]:
(OS )通常每个套接字地址(协议/网络地址/端口)只允许使用一次。 : AH00072: mak
e_sock: could not bind to address 0.0.0.0:
AH00451: no listening sockets available, shutting down
AH00015: Unable to open logs D:\Apache24\bin>
这里443端口被占用,我们可以通过netstat -ano查询那个进程在使用这个端口
参数解释:
-a 显示所有连接和侦听端口。
-n 以数字形式显示地址和端口号。
-o 显示拥有的与每个连接关联的进程 ID。
结果如下:
D:\Apache24\bin>netstat -ano 活动连接 协议 本地地址 外部地址 状态 PID
TCP 0.0.0.0: 0.0.0.0: LISTENING
TCP 0.0.0.0: 0.0.0.0: LISTENING
TCP 0.0.0.0: 0.0.0.0: LISTENING
TCP 0.0.0.0: 0.0.0.0: LISTENING
TCP 0.0.0.0: 0.0.0.0: LISTENING
TCP 0.0.0.0: 0.0.0.0: LISTENING
TCP 0.0.0.0: 0.0.0.0: LISTENING
TCP 0.0.0.0: 0.0.0.0: LISTENING
TCP 0.0.0.0: 0.0.0.0: LISTENING
TCP 0.0.0.0: 0.0.0.0: LISTENING
TCP 0.0.0.0: 0.0.0.0: LISTENING
TCP 0.0.0.0: 0.0.0.0: LISTENING
TCP 127.0.0.1: 0.0.0.0: LISTENING
TCP 127.0.0.1: 0.0.0.0: LISTENING
TCP 127.0.0.1: 0.0.0.0: LISTENING
TCP 127.0.0.1: 127.0.0.1: ESTABLISHED
TCP 127.0.0.1: 0.0.0.0: LISTENING
TCP 127.0.0.1: 127.0.0.1: ESTABLISHED
TCP 127.0.0.1: 127.0.0.1: ESTABLISHED
TCP 127.0.0.1: 127.0.0.1: ESTABLISHED
TCP 127.0.0.1: 127.0.0.1: SYN_SENT
TCP 172.18.62.201: 0.0.0.0: LISTENING
TCP 172.18.62.201: 111.161.81.209: CLOSE_WAIT
TCP 172.18.62.201: 111.161.81.209: CLOSE_WAIT
TCP 172.18.62.201: 111.161.81.209: CLOSE_WAIT
TCP 172.18.62.201: 111.161.81.209: CLOSE_WAIT
TCP 172.18.62.201: 112.64.237.239: TIME_WAIT
TCP 172.18.62.201: 92.51.156.100: ESTABLISHED
TCP 172.18.62.201: 111.161.81.209: CLOSE_WAIT
TCP 172.18.62.201: 112.90.86.25: TIME_WAIT
TCP 172.18.62.201: 183.60.16.21: TIME_WAIT
TCP 172.18.62.201: 183.60.16.21: TIME_WAIT
TCP 172.18.62.201: 112.90.86.25: TIME_WAIT
TCP 172.18.62.201: 61.137.188.200: TIME_WAIT
TCP 172.18.62.201: 61.135.169.125: ESTABLISHED
TCP 172.18.62.201: 111.206.76.33: ESTABLISHED
TCP 172.18.62.201: 111.206.76.33: ESTABLISHED
TCP 172.18.62.201: 111.206.76.33: ESTABLISHED
TCP 172.18.62.201: 111.206.76.32: ESTABLISHED
TCP 172.18.62.201: 111.206.76.32: TIME_WAIT
TCP 172.18.62.201: 61.135.169.121: ESTABLISHED
TCP 172.18.62.201: 61.135.169.121: TIME_WAIT
TCP 172.18.62.201: 61.135.169.121: ESTABLISHED
TCP 172.18.62.201: 61.135.169.121: TIME_WAIT
TCP 172.18.62.201: 23.59.139.27: TIME_WAIT
TCP 172.18.62.201: 23.59.139.27: TIME_WAIT
TCP 172.18.62.201: 61.135.169.125: ESTABLISHED
TCP 172.18.62.201: 61.135.169.121: ESTABLISHED
TCP 172.18.62.201: 61.135.169.125: ESTABLISHED
TCP 172.18.62.201: 223.202.6.26: ESTABLISHED
TCP 172.18.62.201: 223.202.6.26: TIME_WAIT
TCP 172.18.62.201: 202.106.182.252: TIME_WAIT
TCP 172.18.62.201: 123.125.29.224: ESTABLISHED
TCP 172.18.62.201: 123.125.29.224: TIME_WAIT
TCP 172.18.62.201: 124.95.163.253: TIME_WAIT
TCP 172.18.62.201: 124.95.163.253: TIME_WAIT
TCP 172.18.62.201: 124.95.163.253: TIME_WAIT
TCP 172.18.62.201: 124.95.163.253: FIN_WAIT_1
TCP 172.18.62.201: 124.95.163.253: TIME_WAIT
TCP 172.18.62.201: 124.95.163.253: TIME_WAIT
TCP 172.18.62.201: 218.30.115.254: TIME_WAIT
TCP 172.18.62.201: 124.95.163.253: TIME_WAIT
TCP 172.18.62.201: 124.40.53.35: ESTABLISHED
TCP 172.18.62.201: 218.60.106.89: ESTABLISHED
TCP 172.18.62.201: 218.60.106.89: ESTABLISHED
TCP 172.18.62.201: 218.60.106.89: ESTABLISHED
TCP 172.18.62.201: 23.42.177.49: ESTABLISHED
TCP 172.18.62.201: 124.40.53.35: ESTABLISHED
TCP 172.18.62.201: 124.95.163.253: TIME_WAIT
TCP 172.18.62.201: 124.95.163.253: TIME_WAIT
TCP 172.18.62.201: 1.1.1.1: SYN_SENT
TCP 172.18.62.201: 123.125.125.85: TIME_WAIT
TCP 172.18.62.201: 125.39.120.82: SYN_SENT
TCP 192.168.116.1: 0.0.0.0: LISTENING
TCP 192.168.253.1: 0.0.0.0: LISTENING
TCP [::]: [::]: LISTENING
TCP [::]: [::]: LISTENING
TCP [::]: [::]: LISTENING
TCP [::]: [::]: LISTENING
TCP [::]: [::]: LISTENING
TCP [::]: [::]: LISTENING
TCP [::]: [::]: LISTENING
TCP [::]: [::]: LISTENING
TCP [::]: [::]: LISTENING
TCP [::]: [::]: LISTENING
UDP 0.0.0.0: *:*
UDP 0.0.0.0: *:*
UDP 0.0.0.0: *:*
UDP 0.0.0.0: *:*
UDP 0.0.0.0: *:*
UDP 0.0.0.0: *:*
UDP 0.0.0.0: *:*
UDP 0.0.0.0: *:*
UDP 0.0.0.0: *:*
UDP 0.0.0.0: *:*
UDP 0.0.0.0: *:*
UDP 0.0.0.0: *:*
UDP 0.0.0.0: *:*
UDP 0.0.0.0: *:*
UDP 0.0.0.0: *:*
UDP 127.0.0.1: *:*
UDP 127.0.0.1: *:*
UDP 172.18.62.201: *:*
UDP 172.18.62.201: *:*
UDP 172.18.62.201: *:*
UDP 172.18.62.201: *:*
UDP 192.168.116.1: *:*
UDP 192.168.116.1: *:*
UDP 192.168.116.1: *:*
UDP 192.168.116.1: *:*
UDP 192.168.253.1: *:*
UDP 192.168.253.1: *:*
UDP 192.168.253.1: *:*
UDP 192.168.253.1: *:*
UDP [::]: *:*
UDP [::]: *:*
UDP [::]: *:*
UDP [::]: *:*
UDP [::]: *:*
UDP [fe80::481a:1efd:d5d4:a87b%]: *:* UDP [fe80::481a:1efd:d5d4:a87b%]: *:* UDP [fe80::481a:1efd:d5d4:a87b%]: *:* UDP [fe80:::851f::17f1%]: *:* UDP [fe80:::851f::17f1%]: *:* UDP [fe80:::5b85:a10c:3cb7%]: *:* UDP [fe80:::5b85:a10c:3cb7%]: *:* UDP [fe80:::5b85:a10c:3cb7%]: *:* D:\Apache24\bin>
这个结果太多了,加个findstr命令查一下
D:\Apache24\bin>netstat -ano|findstr :
TCP 0.0.0.0: 0.0.0.0: LISTENING
TCP [::]: [::]: LISTENING D:\Apache24\bin>
可以看到PID为2472的进程占用了这个端口。
这是可以用进程管理器查看是那个进程占用,也可以用tasklist命令查看
D:\Apache24\bin>tasklist 映像名称 PID 会话名 会话# 内存使用
========================= ======== ================ =========== ============
System Idle Process Services K
System Services K
smss.exe Services , K
csrss.exe Services , K
wininit.exe Services , K
services.exe Services , K
lsass.exe Services , K
svchost.exe Services , K
svchost.exe Services , K
nvvsvc.exe Services , K
QQPCRTP.exe Services , K
suservice.exe Services K
svchost.exe Services , K
svchost.exe Services , K
svchost.exe Services , K
svchost.exe Services , K
svchost.exe Services , K
spoolsv.exe Services , K
wlanext.exe Services , K
conhost.exe Services , K
svchost.exe Services , K
svchost.exe Services , K
TeamViewer_Service.exe Services , K
vmnat.exe Services , K
vmware-authd.exe Services , K
vmnetdhcp.exe Services , K
vmware-usbarbitrator64.ex Services , K
vmware-hostd.exe Services , K
svchost.exe Services , K
svchost.exe Services , K
SearchIndexer.exe Services , K
audiodg.exe Services , K
csrss.exe Console , K
winlogon.exe Console , K
dwm.exe Console , K
nvxdsync.exe Console , K
nvvsvc.exe Console , K
TeamViewer.exe Console , K
taskhostex.exe Console , K
explorer.exe Console , K
ChsIME.exe Console , K
tv_w32.exe Console , K
tv_x64.exe Console , K
nvtray.exe Console , K
SogouImeBroker.exe Console , K
SogouImeLoader.exe Console , K
SogouCloud.exe Console , K
vmware-tray.exe Console , K
QQPCTray.exe Console , K
QQPCNetFlow.exe Console , K
QQPCRealTimeSpeedup.exe Console , K
8021x.exe Console , K
dllhost.exe Console , K
firefox.exe Console , K
plugin-container.exe Console , K
FlashPlayerPlugin_17_0_0_ Console , K
FlashPlayerPlugin_17_0_0_ Console , K
QQProtect.exe Console , K
QQ.exe Console , K
TXPlatform.exe Console , K
360AP.exe Console , K
360AP.exe Console , K
360AP.exe Console , K
cmd.exe Console , K
conhost.exe Console , K
notepad.exe Console , K
SogouSmartInfo.exe Console , K
tasklist.exe Console , K
WmiPrvSE.exe Services , K D:\Apache24\bin>
加findstr的命令结果
D:\Apache24\bin>tasklist |findstr
vmware-hostd.exe Services , K D:\Apache24\bin>
笔者这里是虚拟机占用,解决方法要么关闭服务器进程/服务,要么换端口号,笔者这里换端口号
打开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.
#
<IfModule ssl_module>
#Include conf/extra/httpd-ssl.conf
Include conf/extra/httpd-ahssl.conf
SSLRandomSeed startup builtin
SSLRandomSeed connect builtin
</IfModule>
从上面的文字可以看出ssl的配置文件在conf/extra/httpd-ahssl.conf目录下(注意:并不在conf/extra/httpd-ssl.conf目录,这一句被注释掉了)
将其中的443改成其他端口,如1443
第一处(Line 18)
Listen
改成
Listen 1
第二处(Line 134,136)
<VirtualHost _default_:443>
SSLEngine on
ServerName localhost:443
SSLCertificateFile "${SRVROOT}/conf/ssl/server.crt"
SSLCertificateKeyFile "${SRVROOT}/conf/ssl/server.key"
DocumentRoot "${SRVROOT}/htdocs"
# DocumentRoot access handled globally in httpd.conf
CustomLog "${SRVROOT}/logs/ssl_request.log" \
"%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
<Directory "${SRVROOT}/htdocs">
Options Indexes Includes FollowSymLinks
AllowOverride AuthConfig Limit FileInfo
Require all granted
</Directory>
</virtualhost>
改成
<VirtualHost _default_:1443>
SSLEngine on
ServerName localhost:1443
SSLCertificateFile "${SRVROOT}/conf/ssl/server.crt"
SSLCertificateKeyFile "${SRVROOT}/conf/ssl/server.key"
DocumentRoot "${SRVROOT}/htdocs"
# DocumentRoot access handled globally in httpd.conf
CustomLog "${SRVROOT}/logs/ssl_request.log" \
"%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
<Directory "${SRVROOT}/htdocs">
Options Indexes Includes FollowSymLinks
AllowOverride AuthConfig Limit FileInfo
Require all granted
</Directory>
</virtualhost>
第三处(Line 150,152)
<VirtualHost *:443>
SSLEngine on
ServerName serverone.tld:443
SSLCertificateFile "${SRVROOT}/conf/ssl/serverone.crt"
SSLCertificateKeyFile "${SRVROOT}/conf/ssl/serverone.key"
DocumentRoot "${SRVROOT}/htdocs"
CustomLog "${SRVROOT}/logs/ssl_request.log" \
"%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
<Directory "${SRVROOT}/htdocs">
Options Indexes Includes FollowSymLinks
AllowOverride AuthConfig Limit FileInfo
Require all granted
</Directory>
</virtualhost>
改成
<VirtualHost *:1443>
SSLEngine on
ServerName serverone.tld:1443
SSLCertificateFile "${SRVROOT}/conf/ssl/serverone.crt"
SSLCertificateKeyFile "${SRVROOT}/conf/ssl/serverone.key"
DocumentRoot "${SRVROOT}/htdocs"
CustomLog "${SRVROOT}/logs/ssl_request.log" \
"%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
<Directory "${SRVROOT}/htdocs">
Options Indexes Includes FollowSymLinks
AllowOverride AuthConfig Limit FileInfo
Require all granted
</Directory>
</virtualhost>
第四处(Line 165,167)
<VirtualHost *:>
SSLEngine on
ServerName servertwo.tld:
SSLCertificateFile "${SRVROOT}/conf/ssl/servertwo.crt"
SSLCertificateKeyFile "${SRVROOT}/conf/ssl/servertwo.key"
DocumentRoot "${SRVROOT}/htdocs"
CustomLog "${SRVROOT}/logs/ssl_request.log" \
"%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
<Directory "${SRVROOT}/htdocs">
Options Indexes Includes FollowSymLinks
AllowOverride AuthConfig Limit FileInfo
Require all granted
</Directory>
</virtualhost>
改成
<VirtualHost *:>
SSLEngine on
ServerName servertwo.tld:
SSLCertificateFile "${SRVROOT}/conf/ssl/servertwo.crt"
SSLCertificateKeyFile "${SRVROOT}/conf/ssl/servertwo.key"
DocumentRoot "${SRVROOT}/htdocs"
CustomLog "${SRVROOT}/logs/ssl_request.log" \
"%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
<Directory "${SRVROOT}/htdocs">
Options Indexes Includes FollowSymLinks
AllowOverride AuthConfig Limit FileInfo
Require all granted
</Directory>
</virtualhost>
如果提示80端口占用,一般是IIS服务启动占用,解决方法也是两种,关闭IIS服务或者改端口,80端口在httpd.conf配置文件里面改
这时再用命令行输入
httpd.exe
不报错说明启动成功
浏览器打开http://localhost
看到Apache Haus的图标和It Works界面说明配置成功
将apache注册为系统服务
在管理员模式下启动命令行,输入httpd -k install
D:\Apache24\bin>httpd -k install
Installing the 'Apache2.4' service
The 'Apache2.4' service is successfully installed.
Testing httpd.conf....
Errors reported here must be corrected before the service can be started. D:\Apache24\bin>
这是可以通过ApacheMonitor.exe界面控制apache服务器启动关闭重启
也可以执行以下命令来控制
httpd -k start
httpd -k stop
httpd -k restart