搭建web服务器
安装web服务器软件
我们选择一个比较常用的 Web 服务器软件:Apache HTTP Server,保证安装目录路径中不要 有中文。
由于最新的 Apache 已经不提供 Windows 的安装版本了,所以我们这里使用的是解压版。
下载地址:https://www.apachelounge.com/download/
使用说明:https://httpd.apache.org/docs/current/platform/windows.html
安装方式如下
先解压到纯英文路径的文件夹,然后执行以下命令:
#注意:需要使用管理员身份运行命令行!!! # 切换到 Apache 解压路径中的 bin 目录
$ cd <解压目录>/bin
安装 Apache 服务,‐n 参数是指定服务名称
$ httpd.exe ‐k install ‐n "Apache"
#如果需要卸载 Apache,可以执行以下命令
$ httpd.exe ‐k uninstall ‐n "Apache"
执行安装命令过后会报一个错,原因是默认的配置文件有问题,需要先调整一下配置文件 conf/httpd.conf ,才能 正常启动服务。
找到对应行,修改为自己的解压路径
修改完以后,执行以下命令重新测试配置文件是否通过。
$ httpd.exe ‐t
通过错误信息得知,这里是因为另外一个地方配置的目录不存在导致的,所以接着调整 DocumentRoot 选项:
改为:
然后重新执行 httpd.exe -t 测试配置文件,这时候应该提示 Syntax OK 。
如有ServerName 的警告提示,不用管它,暂时还不会影响我们接下来的使用和操作,后续可自行配置。
接着运行以下命令重新启动 Apache 服务:
# 注意:需要使用管理员身份运行命令行!!!
$ httpd.exe ‐k start ‐n "Apache"
# 重新启动 Apache 服务
$ httpd.exe ‐k restart ‐n "Apache"
# 停止 Apache 服务
$ httpd.exe ‐k stop ‐n "Apache"
回到浏览器中,地址栏输入:http://localhost/,回车访问,这时正常应该看到 It works!
如果出现 Forbidden 情况,确保配置文件 httpd.conf 中 ( DocumentRoot 之后)的 Directory 配 置的与 DocumentRoot 路径相同 !!!