Apache 服务器下载及安装

Windows Apache(ApacheHaus)安装配置教程

转自:  http://www.cnblogs.com/xyb930826/p/5444718.html

1,Apache下载

选择一个版本,点击Download

点击File For Microsoft Windows

由于Apache HTTP Server官方不提供二进制(可执行)的发行版,所以我们选择一些贡献者编译完成的版本,我们选择第一个ApacheHaus

点击ApacheHaus,进入下载页

选择其中一个版本,如果你的Windows还没安装对应的VC环境的话,选择对应的VCRedistribute版本下载安装。我选择Apache 2.4VC9版,因为我的电脑中已经安装了VC9的环境。

点击JumpLinks下第一行的某一个版本,下载对应压缩包。

2,配置Apache之一--httpd.conf

解压后进入里面Apache22(最后两位数字可能不同)文件夹,使用文本编辑器(推荐ultraedit)打开conf文件夹中的httpd.conf配置文件

找到ServerRoot选项,设置Apache目录,大约在35行左右,将其改成你的Apache程序的文件夹,例

1
ServerRoot "C:/Users/myPC/Downloads/httpd-2.2.31-x86-r3/Apache22"

找到Listen选项,设置端口,大约46行,一般不修改,使用默认80,在开启服务器前请保证80端口未被占用

找到DocumentRoot选项,修改服务器根目录,例:

1
DocumentRoot "F:/"

请保证此目录存在,否则服务器无法正常启动

修改Directory,保证其与服务器根目录相同,只修改下面的第一行中引号部分

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<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选项,设置服务器脚本目录,大约326行,一般将其设置为Apache目录下的cgi-bin文件夹

1
ScriptAlias /cgi-bin/ "C:/Users/myPC/Downloads/httpd-2.2.31-x86-r3/Apache22/cgi-bin"

找到随后的Directory选项,设置脚本目录,大约342行,需要将其设置为和前面的ScriptAlias目录相同

1
2
3
4
5
6
<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配置

如果你这使启动服务,一般会出现下面的消息对话框:

提示

Windows不能在本地计算机启动Apache2.2。有关更多信息,查阅系统日志文件。如果这是非Microsoft服务,请与厂商联系,并参考特定服务器错误代码1。

确定此问题的原因:

右键  计算机,点击管理->Windows日志->应用程序,显示如下

 

这是由于SSL配置不正确所产生的,下面说一下解决办法。

打开Apache程序目录下的conf/extra/httpd-ahssl.conf文件,配置VirtualHost选项,有三处名为VirtualHost的选项,均需修改。

第一个在107行左右。

在110行左右,将其中的SSLCertificateFile改为:Apache所在目录/conf/ssl/server.crt

在111行左右,将SSLCertificateKeyFile改为:Apache所在目录/conf/ssl/server.key

在112行左右,将DocumentRoot改为你的服务器根目录

在126行左右,将CustomLog改为:Apache所在目录/logs/ssl_request.log,这个不改的话也会错。一般会出现如下错误:

 

Apache2.2服务由于下列服务特定错误而终止:函数不正确。

改成的效果:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<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行还有另外两个VirtualHost,均需修改上述的四个选项

例:

130行

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<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行

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<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 >

上述的两个VirtualHost均需修改四处

这样,Apache就算配置完了,如果还有问题,可能还需配置./conf/extra/httpd-ssl.conf,配置方法和配置VirtualHost的相似

4,启动Apache HTTP Server

使用Windows命令行以管理员身份进入Apache程序的文件夹下的bin文件夹,输入httpd -k install,完成Apache服务的安装。

然后双击bin目录下的ApacheMonitor.exe,点击右边的start启动服务器,如果正常,如下图:

测试一下:

5,其它

卸载Apache HTTP Server:

管理员身份进入bin目录,使用httpd -k uninstall 移除服务

使用httpd -w -n "Apache2" -k start命令启动服务器 可以显示启动过程中的日志,便于分析错误。

分类: 服务器
1
0
«上一篇: Windows程序设计(第五版)学习:第四章 文本输出
»下一篇: React学习之一:React初探
posted @ 2016-04-29 13:05 请缨提旅 阅读( 2948) 评论( 0) 编辑 收藏
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值