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.