Apache的默认配置文件是conf\httpd.conf,但也可以准备另一个配置文件在启动Apache时进行指定。

指定配置文件启动Apache

指定配置文件启动Apache使用 -f 选项,具体命令如下。

httpd -f configFile

-f 选项后面指定配置文件的全路径。

为了实验准备了新配置文件 conf\httpd_test.conf 文件。

为了确认是否读取了指定的配置文件,在 conf\httpd_test.conf 上进行了如下修改。

DocumentRoot "${SRVROOT}\docs_test"
<Directory "${SRVROOT}\docs_test">
    #
    # 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:
    #   AllowOverride FileInfo AuthConfig Limit
    #
    AllowOverride None

    #
    # Controls who can get stuff from this server.
    #
    Require all granted
</Directory>

并且在网站根目录下,创建了index.html文件。

准备完成,在命令行上执行如下命令。

C:\pg\Apache\Apache24\bin\httpd -f C:\pg\Apache\Apache24\conf\httpd_test.conf

指定配置文件启动Apache之后,启动浏览器输入 http://localhost/ 访问Apache。

可以确认到Apache返回的是根目录下的index.html的内容,至此我们可以确定启动Apache时指定配置文件有效。

介绍了指定配置文件启动Apache的方法。