When I first started to learn PHP, configure the Apache virtual directory is really broken scalp, did not understand the principle, so it is difficult.
1. Open the "conf/httpd.conf" file under the Apache installation directory, find "Include conf/extra/httpd-vhosts.conf" and remove the "#" in front (uncomment). Warm tip: Change the configuration file is the best habit is to copy a copy, to prevent errors can be restored after.
2. Open the "conf/extra/httpd-vhosts.conf" file under the Apache installation directory and copy the following code ,
The code is as follows |
Copy Code |
<virtualhost *:80> ServerAdmin webmaster@dummy-host2.test.com DocumentRoot "D:/lamp/apache2/docs/dummy-host2.test.com" ServerName dummy-host2.test.com ErrorLog "Logs/dummy-host2.test.com-error.log" Customlog "Logs/dummy-host2.test.com-access.log" common </VirtualHost> |
Then need to leave two lines on the line, "documentroot" means that you want to point to the site of the following directory, "ServerName" is the virtual domain name, the other "ErrorLog" Log what can be omitted to delete.
The code is as follows |
Copy Code |
<virtualhost *:80> DocumentRoot "E:/web" ServerName www.111cn.net </VirtualHost> |
3. Open "hosts" file in "C:windowssystem32driversetc", add one line "127.0.0.1 www.111cn.net". This file is a number of commonly used URL domain name and its corresponding IP address to establish an association "database", when the user in the browser to enter a need to log in the URL, the system will first automatically find the corresponding IP address from the Hosts file, once found, the system will immediately open the corresponding Web page, if not found, Then the system will submit the URL to DNS domain name resolution server for IP address resolution.
4. Finally, don't forget to restart the Apache service.
Working principle: When you open the browser input "http://www.111cn.net", the system will first automatically find the corresponding IP address from the Hosts file, Then found the 127.0.0.1, when the local Apache received the request, to "conf/extra/httpd-vhosts.conf" file inside to find the corresponding information, so as to achieve the entire process!
Multi-Host header bindings
(is to bind a number of domain names on one port, and then each domain can point to a different directory for access, the main head is the description of the IIS inside), open the httpd.conf file, at the end of the file add the following content
#多主机头配置无需放在特定的节点下面, typically directly at the bottom of the configuration file
#NameVirtualHost addr[:p ort] Specify an IP address (and port) for a domain based virtual host
# Declares that the host header must be added with this instruction, no host header configuration will not take effect
#VirtualHost节点下面ServerName就是要绑定的域名, DocumentRoot represents the directory to which this domain name points
# If you are testing this machine, do a domain binding in hosts such as 127.0.0.1 www.mysite1.com
The code is as follows |
Copy Code |
Namevirtualhost *:8080 <virtualhost *:8080> ServerName www.111cn.net DocumentRoot "D:program Filesapache2.2htdocs" </VirtualHost> <virtualhost *:8080> ServerName www.111cn.net DocumentRoot "D:codemysite" </VirtualHost> |
After the configuration, restart the Apache service, browser input www.mysite1.com:8080, will be automatically directed to the D:program Filesapache2.2htdocs site
Alias Bindings
The code is as follows |
Copy Code |
<virtualhost *:80= "" > ServerName www. domain name. com #主机名 serveralias domain 1 Domain name two #别名 separated by a space between each domain DocumentRoot "/var/www/rsjy" #所在目录 </virtualhost> |
The code is as follows |
Copy Code |
<virtualhost *:80= "" > ServerName *. domain name. com #主机名 This is the two-level domain name that binds all the primary domains. DocumentRoot "/var/www/rsjy" #所在目录 </virtualhost> |
multi-domain binding