Linux9.6 httpd Default Virtual Host

Source: Internet
Author: User

Can be understood as, a server ran a number of sites, both can access Baidu and can access QQ, on the use of a httpd service, a site multiple domain names, each site is a corresponding virtual host.

httpd configuration file DocumentRoot "/usr/local/apache2.4/htdocs" Why can access to 1.php under Htdocs, just because of this documentroot this parameter defines the folder
Domain name defined by ServerName

In the Windows platform to modify the hosts, the file defines the domain name IP, you can point IP to a domain name, on win CMD test success

c:\windows\system32\drivers\etc# Copyright (c) 1993-2009 Microsoft corp.## This was a sample HOSTS file used by Microsoft T CP/IP for windows.## This file contains the mappings of IP addresses to host names. each# entry should is kept on a individual line.  The IP address should# is placed in the first column followed by the corresponding host name.# the IP address and the host Name should is separated by at least one# space.## Additionally, comments (such as these) may is inserted on individual# Lines or following the machine name denoted by a ' # ' symbol.## for example:##          # so Urce server#              # x client host# localhost name resolution is handled within DNS itself. #1       localhost#::1             localhost192.168.212.130


In the httpd configuration file

ServerName only defined a domain name, the default host for Apache, that is, any domain name, as long as point to this IP, will access to this site, this site is the default host. This brings the problem, if the machine runs multiple domain names, do not want all domain names to point to this site, all need to configure a virtual host in the httpd configuration file # virtual Hosts#include conf/extra/httpd-vhosts.conf

After you open the comment, the servername and DocumentRoot in the previous httpd configuration file will be invalidated

Vhosts configuration file, each virtualhost is a virtual host, is a site, the first is the default virtual host, that is, access to IP can be accessed, regardless of any domain name resolution to this IP, will visit the first, so generally we put the default virtual host into empty.

[[email protected] htdocs]# vi/usr/local/apache2.4/conf/extra/httpd-vhosts.conf<virtualhost *:80> DocumentRoot "/data/wwwroot/" #网站根目录 ServerName #网站域名 serveralias W #网站别名 errorlog "Logs/" Customlog "Logs/" Common</vi Rtualhost><virtualhost *:80> documentroot "/data/wwwroot/" ServerName serveralias Www.exa errorlog "Logs/" Customlog "Logs/" common</virtualhost>[[email&nb Sp;protected] htdocs]# mkdir-p/data/wwwroot/[[email protected] htdocs]# mkdir/data/wwwroot/[[ Email protected] htdocs]# vim/data/wwwroot/[[email protected] htdocs]# vim/data/wwwroot /[[email protected] htdocs]# vi/etc/hosts127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4::1 localhost LocAlhost.localdomain localhost6 localhost6.localdomain6192.168.212.130[[email protected] htdocs] # ping abc.comping ( (+) bytes of data.64 bytes from ( Icmp_seq=1 ttl= time=0.070 ms^ ping statistics---3 packets transmitted, 3 received, 0% packet loss, time 2000msrtt min/avg /max/mdev = 0.051/0.058/0.070/0.008 ms[[email protected] htdocs]# Curl[[email protected] htdocs]# Curl[[email protected] htdocs]# Curl default is the default host


Linux9.6 httpd 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: 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.