Apache配置本地web服务

1. 下载并安装Apache Http Server
下载:我这里是下载的2.2.25版本的,安装环境为Windows;
下载链接: http://rj.baidu.com/soft/detail/14824.html?ald
安装:安装比较简单,直接下一步;后面会让填一些信息,按照格式填就好了;

2.配置Apache

在安装目录下去打开Apache配置文件“httpd.conf”:我的安装目录为D:\Program Files\Apache Software Foundation\Apache2.2,所以我的配置文件位置D:\Program Files\Apache Software Foundation\Apache2.2\conf。
具体配置:

  • “下面配置文件中,#”为注释标记
  • 为了避免服务器端口号与其他应用端口号使用产生冲突,找到如下代码,将这里这里的监听端口号“Listen 80”修改为“Listen 8080”。如下:
# 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 
  • 找到ServerName, 配置服务器域名,这里由于我没有申请相应域名,直接设置为本机回送地址127.0.0.1,端口号同样设置为8080.如下:
# 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 127.0.0.1:8080
  • 找到DocumentRoot,配置本地web工程根目录(即存放需要的网页的位置),我这里在D盘下创建了一个名为”www“的文件夹,故而把路径配置为:DocumentRoot “D:/www”。如下:
#
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
DocumentRoot "D:/www"
  • 找到如下代码段,配置指定路径下的文件访问权限。先将修改为与上面路径相同,即
#
# Each directory to which Apache has access can be configured with respect
# to which services and features are allowed and/or disabled in that
# directory (and its subdirectories). 
#
# First, we configure the "default" to be a very restrictive set of 
# features.  
#
<Directory "D:www/">
    Options FollowSymLinks
    AllowOverride None
    Order deny,allow
    Allow from all
    Satisfy all 
</Directory>
  • 设置默认打开的网页,即主页。找到DirectoryIndex代码段。在后面添加默认打开的文件名(包括后缀),优先级从左到右递减。
#
# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
#
<IfModule dir_module>
    DirectoryIndex index.html index.htm
</IfModule>

基本配置到此结束,接下来可以测试一下配置结果。 3. 测试配置结果
  • 将自己写的网页放到D:/www路径下;

  • 开浏览器,输入网址http://127.0.0.1:8080/,将显示自己 网页中的结果。如下图这里写图片描述

  • 也可以通过局域网内部IP访问,输入自己主机IP地址:http://192.168.1.100:8080/。结果如下:
    这里写图片描述
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值