欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Apache服务器安装

程序员文章站 2022-07-15 08:09:41
...

1.下载

登录http://httpd.apache.org/download.cgi 这个地址,找到2.4.10,找到file for Windows

进入如下界面后,选择第一项ApacheHaus,这是个第三方下载平台,在它的网站下载独立的Apache会是一个压缩包

2.安装

(1)找到D:\Apache24\conf\httpd.conf文件,用记事本打开,找到:Define SRVROOT 这一项,将其右方的值改为

Define SRVROOT “D:\Apache24

(2)继续找,找到:Listene 80

若你的80端口被占用(可在cmd下用命令netstat -a查看),则将80端口改为别的

保存httpd.conf文件。

(3)接下来需要配置安装Apache的主服务,有了它,Apache才可启动:

打开CMD窗口,输入:"D:\application_software\Apache\bin\httpd.exe" -k install -n apache

切记,包含引号。该命令的意思是,安装apache服务,并将该服务名称命名为apache(你也可以改成别的),回车。

服务安装完毕,完毕后,会自动测试,若有问题,窗口会提示错误,此时,请根据错误自行排查。

正常安装完毕如下图所示:

其中,Errors reported here must be corrected before the service can be started.意思是,若该句话后面有错误信息,则表示服务安装失败,需要先改正错误。若没有,则成功。

(4)在安装目录中,找到D:Apache24\bin\ApacheMonitor.exe可执行文件,双击运行

(5)点击左侧start,启动apache服务。

补充句,从该界面可看出,其可以手动控制服务的开启与关闭,为了节省资源,关闭Apache服务器的时候,请先点击“Stop”关闭apache服务。

当然,该服务也可以在windows系统服务中关闭(建议设置成手动)

(6)打开浏览器,输入访问

http://localhost:端口号 若出现如下图所示界面,则Apache服务器的基本配置完毕,此时apache服务器已经可以运行

Apache服务器安装

3.遇到问题总结

(1)AH00072: make_sock: could not bind to address [::]:443 Aphache启动报443端口占用

这里443端口被占用,我们可以通过netstat -ano查询那个进程在使用这个端口

解决方法:

打开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 443

改成

Listen 1443

第二处(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 *:443>
  SSLEngine on
  ServerName servertwo.tld:443
  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 *:1443>
  SSLEngine on
  ServerName servertwo.tld:1443
  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>