关于Apache的设定保存在httpd.conf文件,安装Apache之后的安装路径及监听端口等需要在配置文件进行修改。在这里介绍安装Apache后的基本设定。

修改安装路径

Apache的配置文件httpd.conf的默认路径是 “Apache安装目录\Apache24\conf” 文件夹。

进行修改之前以防万一先做一个备份,httpd.conf配置文件是文本文件,在这里使用 Visual Studio Code 进行编辑。

在httpd.conf文件搜索 “ServerRoot”。

#
# ServerRoot: The top of the directory tree under which the server's
# configuration, error, and log files are kept.
#
# Do not add a slash at the end of the directory path.  If you point
# ServerRoot at a non-local disk, be sure to specify a local disk on the
# Mutex directive, if file-based mutexes are used.  If you wish to share the
# same ServerRoot for multiple httpd daemons, you will need to change at
# least PidFile.
#
Define SRVROOT "c:/Apache24"

ServerRoot "${SRVROOT}"

ServerRoot是Apache服务器的路径,默认为 “c:\Apache24″。需要根绝实际的安装路径进行修改。具体讲的话,将变量SRVROOT的值修改为Apache的安装目录即可,ServerRoot引用的是SRVROOT的值。

Define SRVROOT "C:\pg\Apache\Apache24"

ServerRoot "${SRVROOT}"

SRVROOT变量不仅用于ServerRoot,其余的地方也会引用SRVROOT变量,例如DocumentRoot。

DocumentRoot "${SRVROOT}\docs_test"
<Directory "${SRVROOT}\docs_test">
・・・・・・
</Directory>

修改Apache的监听端口

接下来设定Apache的监听端口,在文件里搜索 “Listen” 关键字。

#
# Listen: Allows you to bind Apache to specific IP addresses and/or
# ports, instead of the default. See also the <VirtualHost>
# directive.
#
# Change this to Listen on specific IP addresses as shown below to 
# prevent Apache from glomming onto all bound IP addresses.
#
#Listen 12.34.56.78:80
Listen 80

在Listen设定Apache监听的IP地址及端口,一般来讲Web服务器和浏览器的通信使用80端口,默认设定也是80端口(http)。测试环境没有特殊需求的话,无需修改该端口。当我们公布网站时,一般会使用说443端口(https),需要修改为443。

设定ServerName

最后设定ServerName,在文件里搜索 “ServerName” 关键字。

#
# ServerName gives the name and port that the server uses to identify itself.
# This can often be determined automatically, but we recommend you specify
# it explicitly to prevent problems during startup.
#
# If your host doesn't have a registered DNS name, enter its IP address here.
#
#ServerName www.example.com:80

ServerName设定表示服务器的主机名及端口,默认设定是无效的。例如SYS-BLOG.NET设定是”sys-blog.net”,没有指定端口,当省略端口时使用浏览器访问服务器时请求端口。

在这里我们在Windows10上安装了Apache因此ServerName设定为 “localhost:80″。

ServerName localhost:80

修改以上内容后,保存配置文件(httpd.conf)。

介绍了安装Apache后的初始设定。