Apache 2.4虚拟主机配置

虚拟主机指的是在单一机器上运行多个网站 (例如 company1.example.comcompany2.example.com) 。 虚拟主机可以“基于 IP”,即每个 IP 一个站点; 或者“基于名称”, 即每个 IP 多个站点。这些站点运行在同一物理服务器上的事实不会明显的透漏给最终用户。——这是官网解释。


配置Apache虚拟主机。(httpd-vhosts.conf —— Apache虚拟主机配置文件)

基于名称的虚拟主机 (每个 IP 多个站点)

<VirtualHost *:80>
    # This first-listed virtual host is also the default for *:80
    ServerName www.example.com
    ServerAlias example.com 
    DocumentRoot /www/domain
</VirtualHost>

<VirtualHost *:80>
    ServerName other.example.com
    DocumentRoot /www/otherdomain
</VirtualHost>

名词解释

VirtualHost:指虚拟主机的IP/域名,*:80代表所有代表所有80端口的IP

ServerName:虚拟主机名称

ServerAlias:虚拟主机别名,主机别名可以是多个支持通配符

ServerAlias example.com *.example.com

DocumentRoot:网站目录



基于 IP 的虚拟主机 (每个 IP 一个站点)


Listen 172.20.30.40:80
<VirtualHost 172.20.30.40:80>
    ServerAdmin webmaster@www1.example.com
    DocumentRoot /www/vhosts/www1
    ServerName www1.example.com
    ErrorLog /www/logs/www1/error_log
    CustomLog /www/logs/www1/access_log combined
</VirtualHost>
 <pre name="code" class="plain">Listen 172.20.30.50:80
<VirtualHost 172.20.30.50:80>
    ServerAdmin webmaster@www2.example.org
    DocumentRoot /www/vhosts/www2
    ServerName www2.example.org
    ErrorLog /www/logs/www2/error_log
    CustomLog /www/logs/www2/access_log combined
</VirtualHost>

 

名词解释

<pre name="code" class="plain">ServerAdmin  网站管理员邮箱
<pre name="code" class="plain"><pre name="code" class="plain">ErrorLog  错误日志
<pre name="code" class="plain"><pre name="code" class="plain">CustomLog  访问日志

 
 
 
 
 

开启Apache虚拟主机功能(httpd.conf)

搜索Virtual hosts,去掉#Include conf/extra/httpd-vhosts.conf前面的#

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

重启Apache服务


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值