apache 服务虚拟主机配置

 

上一篇博客中,Apache服务已经成功安装,配置,启动成功。

现在对配置文件 进行进一步配置:1.配置文件路径:E:/Apache/Apache24/conf/httpd.conf  

1.端口配置

 修改59行:(不同版本 行号可能不一样),这里默认的是80端口,端口可以配置多个

 #Listen 12.34.56.78:80
 Listen 80

2.根目录配置:

 修改250行:(不同版本 行号可能不一样)

如下是默认配置(Apache服务启动成功后,输入网页地址输入:localhost ,显示的it works 即是来自E:\Apache\Apache24\htdocs\ index.html)

DocumentRoot "${SRVROOT}/htdocs"

<Directory "${SRVROOT}/htdocs">
    Options Indexes FollowSymLinks  //目录下面没有index文件的时候 显示目录
    AllowOverride None   //是否允许覆盖配置
    Require all granted  //访问权限配置
</Directory>

3.默认文档配置(index.html)

当在页面输入目录路径而不是具体的文件路径的时候,默认访问index.html. 其配置如下(279行);

#
# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
#
<IfModule dir_module>
    DirectoryIndex index.html
</IfModule>

 

4.虚拟主机配置:解注释

解注释虚拟主机配置文件(509行)

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

此时,在cmd窗口执行如下命令:

E:\Apache\Apache24\bin>httpd -t
AH00112: Warning: DocumentRoot [E:/Apache/Apache24/docs/dummy-host.example.com] does not exist
AH00112: Warning: DocumentRoot [E:/Apache/Apache24/docs/dummy-host2.example.com] does not exist
Syntax OK

E:\Apache\Apache24\bin>

命令过程如上:

显示两处路径不存在,这是因为刚刚解注释了 Include conf/extra/httpd-vhosts.conf。

打开apache根目录下的: conf/extra/httpd-vhosts.conf

nclude conf/extra/httpd-vhosts.conf配置文件中默认配置了两个虚拟主机:

<VirtualHost *:80>
    ServerAdmin webmaster@dummy-host.example.com
    DocumentRoot "${SRVROOT}/docs/dummy-host.example.com"
    ServerName dummy-host.example.com
    ServerAlias www.dummy-host.example.com
    ErrorLog "logs/dummy-host.example.com-error.log"
    CustomLog "logs/dummy-host.example.com-access.log" common
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin webmaster@dummy-host2.example.com
    DocumentRoot "${SRVROOT}/docs/dummy-host2.example.com"
    ServerName dummy-host2.example.com
    ErrorLog "logs/dummy-host2.example.com-error.log"
    CustomLog "logs/dummy-host2.example.com-access.log" common
</VirtualHost>

修改conf/extra/httpd-vhosts.conf后: 

# * 监听绑定在当前电脑上任意IP的80端口
<VirtualHost *:80>
    # 网站根目录
    DocumentRoot "E:\webProject\baixiu"
  <Directory "E:\webProject\baixiu">
     Options FollowSymLinks
    AllowOverride None
    Require all granted
  </Directory>
	# 域名
    ServerName baixiu.abb
    ErrorLog "logs/baixiu-err.log"
    CustomLog "logs/baixiu.log" common
</VirtualHost>

 

因为  baixiu.abb 域名没有被申请,故为了测试虚拟主机是否配置成功,在hosts文件末尾 增加127.0.0.1       baixiu.abb

5.测试

在浏览器中输入baixiu.abb 成功打开了E:\webProject\baixiu 目录下的index.html 文件  ,表示虚拟主机配置成功

注意,在修改配置文件后,需要重启apache服务 配置才能生效

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值