[httpd]配置虚拟主机。

1 其实很简单,就是一个virtualhost 指令。

<VirtualHost 10.1.2.3:80>
ServerAdmin webmaster@host.example.com
DocumentRoot /www/docs/host.example.com
ServerName host.example.com
ErrorLog logs/host.example.com-error_log
TransferLog logs/host.example.com-access_log
</VirtualHost>


2 。需要开放目录权限 Directory 

但是这里如果这样配的话很可能就是403,禁止访问了。原因是/www/docs这个目录没有开放权限。

centos 的httpd.conf 中这样配置的Directory ,centos中的/etc/httpd/conf/httpd.conf 文件中:

<Directory />
    Options FollowSymLinks
    AllowOverride None
</Directory>
<Directory "/var/www/html">

    Options Indexes FollowSymLinks

    AllowOverride None

    Order allow,deny
    Allow from all

</Directory>


也就是说,只有/var/www/html才有allow的权限。其他目录都是没有的。

我们只需要再添加一个Directory 就可以让/www/docs/host.example.com访问了。

如下:

<VirtualHost 10.1.2.3:80>
ServerAdmin webmaster@host.example.com
DocumentRoot /www/docs/host.example.com
ServerName host.example.com
ErrorLog logs/host.example.com-error_log
TransferLog logs/host.example.com-access_log
<Directory /www/docs/host.example.com>
    Options FollowSymLinks
    AllowOverride None
  Order allow,deny
    Allow from all
</Directory>
</VirtualHost>


3 。验证一下

httpd -t

4. 之后重新即可。

httpd -k restart

5. 配置多域名的虚拟主机。

加个NameVirtualHost 指令即可。

NameVirtualHost *:80

<VirtualHost *:80>
ServerName www.domain.tld
ServerAlias domain.tld *.domain.tld
DocumentRoot /www/domain
</VirtualHost>

<VirtualHost *:80>
ServerName www.otherdomain.tld
DocumentRoot /www/otherdomain
</VirtualHost>



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值