Apache的配置是在httpd.conf文件中完成的,也可以准备一个辅助的配置文件,并将其加载到httpd.conf文件中。 介绍httpd.conf文件的路径,以及如何加载辅助性配置文件。

httpd.conf文件的路径

安装Apache之后的文件构成如下。

Apache的配置文件httpd.conf文件路径位于 “安装目录\Apache24\conf” 目录下。

进行修改之前,为了恢复原配置复制httpd.conf并保存为别的名称。修改httpd.conf文件使用文本编辑器打开文件。(在这里使用Visual Studio Code文本编辑器)。参考:文本编辑器Visual Studio Code(VSCode)的安装及使用

读取补助文件

Apache当前版本,一些配置项被分离到独立的文件中,并根据需要加载到httpd.conf文件。默认的辅助配置文件路径是 “(安装目录)\Apache24\conf\extra\” 目录下。

httpd.conf文件中加载另一个配置文件使用Include指令,例如httpd.conf文件的最后的部分,有如下配置。

# Supplemental configuration
#
# The configuration files in the conf/extra/ directory can be 
# included to add extra features or to modify the default configuration of 
# the server, or you may simply copy their contents here and change as 
# necessary.

# Server-pool management (MPM specific)
#Include conf/extra/httpd-mpm.conf

# Multi-language error messages
#Include conf/extra/httpd-multilang-errordoc.conf

# Fancy directory listings
#Include conf/extra/httpd-autoindex.conf

# Language settings
#Include conf/extra/httpd-languages.conf

# User home directories
#Include conf/extra/httpd-userdir.conf

# Real-time info on requests and configuration
#Include conf/extra/httpd-info.conf

# Virtual hosts
#Include conf/extra/httpd-vhosts.conf

# Local access to the Apache HTTP Server Manual
#Include conf/extra/httpd-manual.conf

# Distributed authoring and versioning (WebDAV)
#Include conf/extra/httpd-dav.conf

# Various default settings
#Include conf/extra/httpd-default.conf

默认配置是注释(每一行的前缀是 “#”),实际上没有读取上面的补助文件。如果需要读取补助文件,需把行首的”#”的去掉。

# Various default settings
Include conf/extra/httpd-default.conf

补助文件 “conf/extra/httpd-default.conf” 将会被读取,既补助文件的配置生效。

介绍了httpd.conf文件的路径及加载补助文件的方法。