Today, when learning PHP, there is 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 different virtual hosts by port
① follow the method of binding a site to prepare
1. First Develop your own website (d:/myblog (stored in the MyBlog directory of D-disk))
2. Configure the httpd.conf file (stored in the Conf folder of the Apache installation directory) and enable httpd-vhosts.conf (remove the # number in front of the second line).
3. Configure the httpd-vhosts.conf file (stored in the extra folder of the Apache installation directory)
4. Add IP and domain name correspondence in the Hosts file
C:/windows/system32/drivers/etc/hosts
5. It is recommended to unregister the DocumentRoot (document root) in the httpd.conf file
6. Test, enter "Http://www.shunping1.com" in the browser to see the site homepage
② Add a new domain name to the IP binding:
1. Developing a new website: d:/myblog2
2. Configure the httpd.conf file (stored in the Conf folder of the Apache installation directory) to add a new virtual host
3. Always allow Apache to listen on port 81 in the httpd.conf file
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: distinguish different domain names through the servername end
1. Develop a new site D:/MYBLOG2
2. In the httpd.conf file, let Apache unblock 81 ports (add # or delete directly)
3. Add the configuration in the httpd-vhosts.conf file (note that the configuration and scenario one here are not the same)
4. Other configurations are the same
record Learning bit, long road, all because of the endless ...
PHP implements a binding of IP (e.g. 127.0.0.1) and multiple domain names (virtual hosts)