Today in the study of PHP, there is such a requirement: an IP (such as: 127.0.0.1) and multiple domain names (virtual host) binding, the following is my solution:
Solution One: differentiate the different virtual hosts through the ports
① the way to bind a site
1. First Develop your own website (d:/myblog (stored in the D-disk MyBlog directory))
2. Configure the httpd.conf file (stored in the Conf folder in the Apache installation directory) and enable httpd-vhosts.conf (the # number in front of the second line is removed).
3. Configure httpd-vhosts.conf files (stored in the extra folder of the Apache installation directory)
4. Add IP and domain name correspondence in Hosts file
C:/windows/system32/drivers/etc/hosts
5. It is recommended to unregister DocumentRoot (document Root), in the httpd.conf file
6. Test, enter "Http://www.shunping1.com" in the browser to see the site home page
② Add a new domain name with this IP binding:
1. Develop a new website: d:/myblog2
2. Configure the httpd.conf file (stored in the Conf folder in the Apache installation directory) to add a new virtual host
3. In the httpd.conf file always let Apache listen to 81 ports
4. Add a new domain name to the Hosts file
5. Test, enter "Http://www.shunping3.com:80" in the browser (must add port name)
Solution Two: differentiate different domain names by servername end
1. Develop a new site D:/MYBLOG2
2. In the httpd.conf file let Apache cancel listening to 81 ports (plus # or delete directly in front)
3. Add the configuration in the httpd-vhosts.conf file (note that the configuration and scenario one is different here)
4. Other configurations are unchanged