Apache Default Virtual Host

Source: Internet
Author: User


In the httpd configuration file, DocumentRoot "/usr/local/apache2.4/htdocs" defines where the root directory of the Web site is, and the domain name is the defined ServerName www.example.com:80 this line

The path of the hosts under Windows

Add a row of native IP domain names in the Hosts file (one IP can correspond to multiple domain names, separated by spaces), you can temporarily assign a domain name to an IP, this is the case that the DNS has not yet taken effect can be done

Linux httpd configuration file, ServerName www.example.com:80 This line is Apache's default virtual host, as long as it is assigned to this IP, it will access to www.example.com:80 this site, This site is called the default virtual host
Search in config file; Extra this keyword, there's a line in it.
#Virtual hosts, this is a virtual host.
#Include conf/extra/httpd-vhosts.conf//Remove the # from the front of the line
Open level two virtual machine host configuration file, which can define multiple servername
#vim/usr/local/apache2.4/conf/extra/httpd-vhosts.conf//Virtual Host profile Path

Configuration file, a virtualhost represents a host, a host represents a Web site
<virtualhost *:80>
ServerAdmin [email protected]//define admin mailbox, can delete
DocumentRoot "/usr/local/apache2.4/docs/dummy-host.example.com"//define site root directory
ServerName dummy-host.example.com//define site name
Serveralias www.dummy-host.example.com//define aliases, can have multiple aliases, but access the same content
Errorlog "Logs/dummy-host.example.com-error_log"//Specify error log
Customlog "Logs/dummy-host.example.com-access_log" common//Specify access Log
</VirtualHost>
This defines a site that defines the site at its core, defines its root directory, and accesses the domain name, noting that only Serveralias can write multiple domain names, servername can only write a
Once the virtual machine host configuration file is in effect, the servername www.example.com:80 defined in the httpd.conf file will be invalidated

This defines two Web sites in a virtual host configuration file
#mkdir/data/wwwroot///Create a Site Directory
#mkdir/data/wwwroot/abc.com
#mkdir/data/wwwroot/111.com
Create a index.php file under the/data/wwwroot/abc.com/index.php//abc.com directory #vim
<?php
echo "ABC.com";
?>
Create a index.php file under the/data/wwwroot/111.com/index.php//111.com directory #vim
<?php
echo "111.com";
?>
#/usr/local/apache2.4/bin/apachectl-t//Check the service for any errors
#/usr/local/apache2.4/bin/apachectl Graceful//Reload

Curl Command
#curl-x192.168.238.128:80 abc.com//Specify abc.com access to the native 192.168.238.1:80 port
or # curl-x192.168.238.128:80 www.abc.com
If the domain name that is accessed is not configured in the virtual machine host configuration file, then he will default to the first paragraph of the configuration file is defined as the first paragraph of the abc.com, this is the default virtual host profile, the virtual host profile is in effect, httpd.conf the master profile defined ServerName www.example:80 and Documentroot=xxx website path will be invalid!

Apache Default Virtual host

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.