Add virtual host configuration + local hosts bound domain name in Apache

Source: Internet
Author: User

1. Local hosts

What is local hosts? We know to access a domain name, get the Server IP address pointed to by the domain name through the DNS server, and then establish a connection with the server through the IP address to complete the rest. So how can we simulate a domain name when there is no domain name in the development process? The answer is the hosts file. Generally, the development environment is under Win, so here we take win as an example. I believe I can find it myself when I play Linux.

Find the c: \ windows \ system32 \ drivers \ etc \ hosts file, open it in notepad, and add a line at the end:

127.0.0.1 www.xxx.com

Save it. Now, when you access www.xxx.com, it actually points to the local IP address 127.0.0.1.

2. Apache Virtual Host Configuration

Assume that Apache is installed in X: \ apache, open X: \ apache \ conf \ httpd first. conf, find "include CONF/extra/httpd-vhosts.conf" If '#' is in front of it to delete it, if there is no such statement, manually add.

Find or create a httpd-vhosts.conf file in the X: \ apache \ conf \ extra directory and add:

<Virtualhost *: 80> DocumentRoot "D:/XAMPP/htdocs" servername localhost </virtualhost> <virtualhost *: 80> DocumentRoot "D: /XAMPP/htdocs/XXX "servername www.xxx.com </virtualhost>



Why do we need to add two <virtruahost> segments? In fact, it is described in this file:

When the VM function is enabled, all requests will enter<Virtruahost>, and the first<Virtruahost> will be used as the default processing configuration, that is, www.xxx.com will enter the second<Virtruahost>, but none of the other matches will enter the first<Virtruahost> Configuration, such as the localhost series.

The VM is simply implemented here. More configuration options are not listed here. Check the manual by yourself.

If you bind multiple IP addresses to a VM on the server, you need to useFor more information about the configuration parameter namevirtualhost, see.

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.