Windows运维_Windows下配置Apache-Haus(Apache2.4)

2024-03-29 15:04

本文主要是介绍Windows运维_Windows下配置Apache-Haus(Apache2.4),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

Windows运维_Windows下配置Apache-Haus(Apache2.4)

Apache Haus 是一个由网站管理员, 开发人员和爱好者组成的社区, 他们更喜欢使用 Apache Web 服务器而不是 IIS。

无论是出于商业还是娱乐目的, Apache 在 Windows 上的使用正在稳步增加, 我们希望通过为人们提供一个可以获得帮助并分享他们在 Windows 上使用 Apache 的经验的地方, 看到这一趋势继续下去。

我们的论坛为人们提供了一个会面, 提问或分享有关 Apache 安装和操作知识的场所, 并帮助他们了解最新技术。

请注意, Apache Haus 不隶属于 Apache 软件基金会, 不受其认可。Apache HTTP Server, Apache 和 Apache 羽毛徽标是 Apache 软件基金会的商标。

The Apache Haus is a community of webmasters, developers and hobbyists who prefer using the Apache Web Server over IIS.

Whether for business or pleasure, the use of Apache on Windows is steadily gaining and we hope to see the trend continue by offering people a place to come where they can get help and share their experiences using Apache on Windows.

Our forums provide the place for people to meet and ask questions or share their knowledge concerning the installation and operation of Apache, as well as helping them keep up to date with the latest technologies.

Please note that the Apache Haus is not affiliated with, or endorsed by, the Apache Software Foundation. The Apache HTTP Server, Apache, and the Apache feather logo are trademarks of The Apache Software Foundation.

Server powered by: Finetworks Ay

  • 由以上 Apache Haus 的申明可知, Apache HTTP Server 官方不提供二进制 (可执行) 的发行版, 所以我们只能选择一些贡献者编译完成的版本, 这里我们当然选择了 Apache Haus。

  • 在 Apache Haus 下载页面 (https://www.apachehaus.com/) 下载 Apache 2.4 Server Binaries (Windows 需要安装对应的 VC 环境)。

Apache Haus 配置 1 - httpd.conf

  • 设置 Apache 目录, 即 ServerRoot 选项, 将其改成你的 Apache 程序的文件夹。

    如果存在 Define SRVROOT “[ApachePath]”, 则修改此处的 [ApachePath]。

    如果只有 ServerRoot “[ApachePath]”, 则修改此处的 [ApachePath]。

    如果既存在 Define SRVROOT, 也存在 ServerRoot “${SRVROOT}”, 则只需要修改 Define SRVROOT “[ApachePath]” 中的 [ApachePath]。

    当然也可以直接修改 ServerRoot “[ApachePath]” 中的 [ApachePath], 只不过灵活性要差一些。

    修改示例:

    Define SRVROOT "D:\Program\Apache24"
    ServerRoot "${SRVROOT}"
    
  • 设置 Apache 服务监听的端口, 即 Listen 选项, 一般不修改, 使用默认 80, 在开启服务器前请保证 80 端口未被占用。

    修改示例:

    Listen 80
    
  • 设置 Apache 服务根目录, 即 DocumentRoot 选项, 是存放 .html 文件的目录, 用户输入 IP地址 + 端口号 (如: 12.34.56.78:80) 能够访问到的目录。

    请保证 DocumentRoot 所设置的目录存在, 否则服务器无法正常启动。

    同时也需要修改随后的 … XML标签中的路径属性, 保证其与服务器根目录相同。

    修改示例:

    DocumentRoot "D:\Program\Apache24\htdocs"
    <Directory "D:\Program\Apache24\htdocs">## 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## Controls who can get stuff from this server.#Require all granted
    </Directory>
    
  • 设置 Apache 的 cgi-bin 路径, 即 ScriptAlias /cgi-bin/ 选项, 通常将其设置为 Apache 目录下的 cgi-bin 文件夹。

    需同时要找到随后的 … XML标签, 设置脚本目录, 需要将其设置为和前面的 ScriptAlias /cgi-bin/ 所指定的目录相同。

    修改示例:

    <IfModule alias_module>## Redirect: Allows you to tell clients about documents that used to # exist in your server's namespace, but do not anymore. The client # will make a new request for the document at its new location.# Example:# Redirect permanent /foo http://www.example.com/bar## Alias: Maps web paths into filesystem paths and is used to# access content that does not live under the DocumentRoot.# Example:# Alias /webpath /full/filesystem/path## If you include a trailing / on /webpath then the server will# require it to be present in the URL.  You will also likely# need to provide a <Directory> section to allow access to# the filesystem path.## ScriptAlias: This controls which directories contain server scripts. # ScriptAliases are essentially the same as Aliases, except that# documents in the target directory are treated as applications and# run by the server when requested rather than as documents sent to the# client.  The same rules about trailing "/" apply to ScriptAlias# directives as to Alias.#ScriptAlias /cgi-bin/ "D:\Program\Apache24\cgi-bin\"</IfModule><IfModule cgid_module>## ScriptSock: On threaded servers, designate the path to the UNIX# socket used to communicate with the CGI daemon of mod_cgid.##Scriptsock logs/cgisock
    </IfModule>#
    # "${SRVROOT}/cgi-bin" should be changed to whatever your ScriptAliased
    # CGI directory exists, if you have that configured.
    #
    <Directory "D:\Program\Apache24\cgi-bin">AllowOverride NoneOptions NoneRequire all granted
    </Directory>
    

Apache Haus 配置 2 - 尝试启动 Apache 服务

  • 配置环境变量: 右键点击 “计算机” -> 属性 -> 高级系统设置 -> 环境变量 -> 编辑 Path -> 新建 -> 添加 “D:\Program\Apache24\bin” 路径

  • 测试环境变量: Win 键 + r 打开 “运行” -> 输入 cmd 打开 Windows 终端 -> 输入 httpd -v 显示 Apache 版本号

  • (如果之前安装并使用过 Nginx, 需要先清除浏览器缓存)

  • 安装 Apache 服务: 以管理员的身份再次打开 Windows 终端, 输入 httpd -k install 安装 Apache 服务 (未安装 Apache 服务可能无法启动 Apache 服务)。

  • 启动 Apache 服务 (方式 1): 打开 Windows 终端, 输入 httpd -k start 启动 Apache 服务。

  • 启动 Apache 服务 (方式 2): 打开 D:\Program\Apache24\bin 目录下的 ApacheMonitor.exe, 点击右边的 start 启动 Apache 服务。

    Windows 系统下 Apache 24.x 常见命令:

    httpd -k install      安装 Apache 服务
    httpd -k uninstall    移除 Apache 服务httpd -k start        启动 Apache 服务
    httpd -k restart      重启 Apache 服务
    httpd -k stop         关闭已安装的 Apache 服务httpd -v              查看 Apache 版本
    httpd -t              查看 Apache 配置文件状态
    
  • 错误处理: (OS 10048)通常每个套接字地址(协议/网络地址/端口)只允许使用一次。 : AH00072: make_sock: could not bind to address [::]:443

    意思就是 443 端口号被占用了

    修改 1: 将 D:\Program\Apache24\conf\extra 中 httpd-ahssl.conf 的 Listen 443 https 修改为 Listen 442 https 或 Listen 444 https

    修改 2: 将 D:\Program\Apache24\conf\extra 中 httpd-ssl.conf 的 Listen 443 修改为 Listen 442 或 Listen 444

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

    右键点击 “计算机” -> 事件查看器 -> Windows 日志 -> 应用程序 -> 查看对应时间出错的应用其 “常规” 或 “详细信息” 中的信息

    错误日志 1:The Apache service nnamed reported the following error:
    >>> Syntax error on line 133 of C:/Users/xyb-C308/Downloads/httpd-2.2.31-x86-r3/Apache22/conf/extra/httpd-ahssl.conf:.错误日志 2:The Apache service nnamed reported the following error:
    >>> SSLCertificateFile 'C:/Apache22/conf/ssl/server.crt' dose not exist or is empty.
    

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

    打开 D:\Program\Apache22\conf\extra\httpd-ahssl.conf 文件, 配置 VirtualHost 选项。

    注意: 可能不止一处名为 VirtualHost 的选项, 均需修改。

    将其中的 SSLCertificateFile 改为 D:/Program/Apache22/conf/ssl/server.crt

    将其中的 SSLCertificateKeyFile 改为 D:/Program/Apache22/conf/ssl/server.key

    将其中的 DocumentRoot 改为你的服务器根目录。

    ##
    ## SSL Virtual Host Context
    ##<VirtualHost _default_:443>SSLEngine onServerName localhost:443SSLCertificateFile "D:/Program/Apache22/conf/ssl/server.crt"SSLCertificateKeyFile "D:/Program/Apache22/conf/ssl/server.key"DocumentRoot "D:/Program/Apache22/htdocs"
    # DocumentRoot access handled globally in httpd.confCustomLog "${SRVROOT}/logs/ssl_request.log" \"%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"<Directory "${SRVROOT}/htdocs">Options Indexes Includes FollowSymLinksAllowOverride AuthConfig Limit FileInfoRequire all granted</Directory>
    </virtualhost>
    

    将其中的 CustomLog 改为 D:/Program/Apache22/logs/ssl_request.log, 这个不改的话也会错, 通常会出现如下错误:

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

    这样, 错误就算处理完了, 如果还有问题, 可能还需配置 D:\Program\Apache22\conf\extra\httpd-ssl.conf, 配置方法和配置 httpd-ahssl.conf 的 VirtualHost 的相似。

Apache Haus 配置 3 - 启动 Apache 服务

  • 配置 Apache 服务 -> 安装 Apache 服务 -> 启动 Apache 服务

  • 整个流程下来没有错误, 或处理完所有错误后, 以后都按以下方式启动 Apache 服务即可。

    启动 Apache 服务 (方式 1): 打开 Windows 终端, 输入 httpd -k start 启动 Apache 服务。

    启动 Apache 服务 (方式 2): 打开 D:\Program\Apache24\bin 目录下的 ApacheMonitor.exe, 点击右边的 start 启动 Apache 服务。

  • 也可以显示启动过程中的日志, 便于分析错误。

    使用 httpd -w -n “Apache2” -k start 命令启动服务器

Apache Haus 配置 4 - 开机启动 Apache 服务

  • 右键点击 “计算机” -> 管理 -> 服务和应用程序 -> 服务 -> 找到 Apache2.4 -> 右键点击 “Apache2.4” -> 属性 -> 修改启动类型

    启动类型说明:

    自动: 开机自动启动

    手动: 每次手动启动

Apache Haus 可选配置 - 配置 PHP-7.x.x 支持

  • 下载 PHP-7.x.x。注意: 需要下载 “线程安全(THREAD SAFE)版”, 如果是 “非线程安全(NOT THREAD SAFE)版”, 则不包含 “php7apache2_4.dll” 库文件。

  • 修改 Apache Haus 的 httpd.conf 文件, 加载 PHP-7.x.x 的支持, 在 httpd.conf 文件末尾添加如下内容:

    # Load PHP7 Module for PHP7 Support.
    LoadModule php7_module D:\Program\PHP-7.4.28-TS-Win32-VC15-X64\php7apache2_4.dll# 将 PHP 配置文件加载到 Apache 配置文件中, 使其共同生效。
    PHPIniDir "D:\Program\PHP-7.4.28-TS-Win32-VC15-X64"
    
  • 修改 Apache Haus 的 httpd.conf 文件, 让 Apache 分配模块工作, 将含有 PHP 代码的 .php 文件分配给 PHP 模块处理, 在 httpd.conf 文件末尾添加如下内容:

    # 让 Apache 分配模块工作, 将含有 PHP 代码的 .php 文件分配给 PHP 模块处理。
    AddType application/x-httpd-php .php
    

    或者:

    # 让 Apache 分配模块工作, 将含有 PHP 代码的 .php 文件分配给 PHP 模块处理。
    <IfModule mod_php7.c>AddType application/x-httpd-php .php
    </IfModule>
    
  • 修改 Apache Haus 的 httpd.conf 文件, 让 Apache 解析 index.php 主页索引文件。

    找到以下内容:

    <IfModule dir_module>DirectoryIndex index.html
    </IfModule>
    

    将找到的 DirectoryIndex 参数末尾添加上 index.php 项目:

    <IfModule dir_module>DirectoryIndex index.html index.php
    </IfModule>
    
  • 重启 Apache 服务, 使 httpd.conf 配置生效。

    httpd -k restart
    

总结

以上就是关于 Windows运维 Windows下配置Apache-Haus(Apache2.4) 的全部内容。

更多内容可以访问我的代码仓库:

https://gitee.com/goufeng928/public

https://github.com/goufeng928/public

这篇关于Windows运维_Windows下配置Apache-Haus(Apache2.4)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/858897

相关文章

nginx 负载均衡配置及如何解决重复登录问题

《nginx负载均衡配置及如何解决重复登录问题》文章详解Nginx源码安装与Docker部署,介绍四层/七层代理区别及负载均衡策略,通过ip_hash解决重复登录问题,对nginx负载均衡配置及如何... 目录一:源码安装:1.配置编译参数2.编译3.编译安装 二,四层代理和七层代理区别1.二者混合使用举例

Java JDK1.8 安装和环境配置教程详解

《JavaJDK1.8安装和环境配置教程详解》文章简要介绍了JDK1.8的安装流程,包括官网下载对应系统版本、安装时选择非系统盘路径、配置JAVA_HOME、CLASSPATH和Path环境变量,... 目录1.下载JDK2.安装JDK3.配置环境变量4.检验JDK官网下载地址:Java Downloads

Linux下进程的CPU配置与线程绑定过程

《Linux下进程的CPU配置与线程绑定过程》本文介绍Linux系统中基于进程和线程的CPU配置方法,通过taskset命令和pthread库调整亲和力,将进程/线程绑定到特定CPU核心以优化资源分配... 目录1 基于进程的CPU配置1.1 对CPU亲和力的配置1.2 绑定进程到指定CPU核上运行2 基于

Spring Boot spring-boot-maven-plugin 参数配置详解(最新推荐)

《SpringBootspring-boot-maven-plugin参数配置详解(最新推荐)》文章介绍了SpringBootMaven插件的5个核心目标(repackage、run、start... 目录一 spring-boot-maven-plugin 插件的5个Goals二 应用场景1 重新打包应用

Java中读取YAML文件配置信息常见问题及解决方法

《Java中读取YAML文件配置信息常见问题及解决方法》:本文主要介绍Java中读取YAML文件配置信息常见问题及解决方法,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要... 目录1 使用Spring Boot的@ConfigurationProperties2. 使用@Valu

Jenkins分布式集群配置方式

《Jenkins分布式集群配置方式》:本文主要介绍Jenkins分布式集群配置方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录1.安装jenkins2.配置集群总结Jenkins是一个开源项目,它提供了一个容易使用的持续集成系统,并且提供了大量的plugin满

PowerShell中15个提升运维效率关键命令实战指南

《PowerShell中15个提升运维效率关键命令实战指南》作为网络安全专业人员的必备技能,PowerShell在系统管理、日志分析、威胁检测和自动化响应方面展现出强大能力,下面我们就来看看15个提升... 目录一、PowerShell在网络安全中的战略价值二、网络安全关键场景命令实战1. 系统安全基线核查

SpringBoot线程池配置使用示例详解

《SpringBoot线程池配置使用示例详解》SpringBoot集成@Async注解,支持线程池参数配置(核心数、队列容量、拒绝策略等)及生命周期管理,结合监控与任务装饰器,提升异步处理效率与系统... 目录一、核心特性二、添加依赖三、参数详解四、配置线程池五、应用实践代码说明拒绝策略(Rejected

SQL Server配置管理器无法打开的四种解决方法

《SQLServer配置管理器无法打开的四种解决方法》本文总结了SQLServer配置管理器无法打开的四种解决方法,文中通过图文示例介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的... 目录方法一:桌面图标进入方法二:运行窗口进入检查版本号对照表php方法三:查找文件路径方法四:检查 S

Linux中SSH服务配置的全面指南

《Linux中SSH服务配置的全面指南》作为网络安全工程师,SSH(SecureShell)服务的安全配置是我们日常工作中不可忽视的重要环节,本文将从基础配置到高级安全加固,全面解析SSH服务的各项参... 目录概述基础配置详解端口与监听设置主机密钥配置认证机制强化禁用密码认证禁止root直接登录实现双因素