How to add multiple virtual hosts under ubuntu14.04 LTS when the lamp installation is complete

Source: Internet
Author: User

When we install the lamp environment, we usually use localhost for local address access, however, when we in the experimental environment, we need to configure multiple domain names, for different access, for example, a localhost and a test.cn two host, add a website test.cn Doing experiments, this is when we need to use the virtual host.


Here I use the PHP environment is Lamp-server, operating system for Ubuntu 14.04 LTS. #号为注释的内容


  1. Add this 127.0.0.1 food.cn under the/etc/hosts.

    127.0.0.1 localhost
    127.0.0.1 test.cn #添加自己需要的域名
    # The following lines is desirable for IPV6 capable hosts
    :: 1 ip6-localhost ip6-loopback
    fe00::0 ip6-localnet
    ff00::0 Ip6-mcastprefix
    Ff02::1 Ip6-allnodes
    Ff02::2 ip6-allrouters

  2. [Email protected]:cat/etc/apache2/sites-enabled/000-default.conf #查看配置文件
    <virtualhost *:80>
    # The SERVERNAME directive sets the request scheme, hostname and port that
    # The server uses to identify itself. This was used when creating
    # redirection URLs. In the context of the virtual hosts, the ServerName
    # specifies hostname must appear in the request ' s Host:header to
    # match this virtual host. For the default virtual host (this file) this
    # value was not decisive as it was used as a last resort host regardless.
    # However, must set it for any further virtual host explicitly.
    #ServerName www.example.com

    ServerAdmin [email protected]
    Documentroot/var/www/html

    # Available Loglevels:trace8, ..., Trace1, debug, info, notice, warn,
    # error, Crit, alert, Emerg.
    # It's 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 more configuration files from conf-available/, which is
    # enabled or disabled at a global level, it's 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 had been globally disabled with "a2disconf".
    #Include conf-available/serve-cgi-bin.conf
    </VirtualHost>

  3. Modify the configuration in the above file, sudo gedit/etc/apache2/sites-enabled/000-default.conf Configure the virtual host, copy and localhost configuration and remove the relevant comments
    [Email Protected]:sudo gedit/etc/apache2/sites-enabled/000-default.conf #修改虚拟主机的配置文件
    <virtualhost *:80>
    # The SERVERNAME directive sets the request scheme, hostname and port that
    # The server uses to identify itself. This was used when creating
    # redirection URLs. In the context of the virtual hosts, the ServerName
    # specifies hostname must appear in the request ' s Host:header to
    # match this virtual host. For the default virtual host (this file) this
    # value was not decisive as it was used as a last resort host regardless.
    # However, must set it for any further virtual host explicitly.
    #ServerName www.example.com

    ServerAdmin [email protected]
    Documentroot/var/www/html

    # Available Loglevels:trace8, ..., Trace1, debug, info, notice, warn,
    # error, Crit, alert, Emerg.
    # It's 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 more configuration files from conf-available/, which is
    # enabled or disabled at a global level, it's 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 had been globally disabled with "a2disconf".
    #Include conf-available/serve-cgi-bin.conf
    </VirtualHost>

    #这里为新添加的虚拟主机, the host name is test.cn
    <virtualhost *:80>
    ServerAdmin test.cn #这里也定义一个域名

    ServerName test.cn #添加自己定义的域名
    Documentroot/var/www/test #添加自己域名所对应的目录
    Errorlog ${apache_log_dir}/error.log
    Customlog ${apache_log_dir}/access.log combined
    </VirtualHost>


  4. Restart Apache Service
    sudo service apache2 restart


  5. Open the browser, enter test.cn that can use this domain name to access their own defined files.



Note: In this configuration process, the most important is to find the virtual host configuration file, in Utubtu Lts is placed in,/etc/apache2/sites-enabled/000-default.conf, open can

This article is from the "Small City Studio" blog, please be sure to keep this source http://xcroom.blog.51cto.com/7941996/1633810

How to add multiple virtual hosts under ubuntu14.04 LTS when the lamp installation is complete

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.