在Ubuntu 14.04 LTS系统中设置Apache虚拟主机

在这个教程中,我会使用Ubuntu 14.04 LTS,并搭建1个测试网站命名目录为“tianmao .我的虚拟机IP192.168.1.128。你可以根据你的需要更改虚拟域名。前提是有了虚拟机的静态ip,

sudo mkdir -p /var/www/tianmao

创建一个静态html访问文件,写些东西并访问

sudo touch index.html

创建虚拟主机配置文件
默认情况下,apache有一个默认的虚拟主机文件叫000-default.conf。我们将会复制000-default.conf文件内容到我们新的虚拟主机配置文件中。

sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/tianmao.conf

确保虚拟主机配置文件末尾包含.conf扩展名。修改tianmao.conf文件以符合需求。

sudo vi /etc/apache2/sites-available/tianmao.conf

<VirtualHost *:80>
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.
        #ServerName www.example.com

        #ServerAdmin webmaster@unixmen1.local
        ServerName www.tianmao.com
        #ServerAlias www.unixmen1.local
        DocumentRoot /var/www/tianmao

        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf
</VirtualHost>

修改虚拟主机文件后,禁用默认的虚拟主机配置(000.default.conf),然后启用新的虚拟主机配置,如下

sudo a2dissite 000-default.conf

sudo a2ensite tianmao.conf

重启apache服务器

sudo service apache2 restart

编辑/etc/hosts文件,

sudo vi /etc/hosts

192.168.1.250 www.tianmao.com

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值