Here, I'll just introduce a simpler and more common way to configure a virtual host. is the name-based virtual host configuration:
First step:
Found in the httpd.conf in the Conf file
| The code is as follows |
Copy Code |
# Virtual Hosts #Include conf/extra/httpd-vhosts.conf Then change the above to read: # Virtual Hosts Include conf/extra/httpd-vhosts.conf |
Step Two:
Locate the httpd-vhosts.conf under the Conf/extra file and add the following code to the last side:
# www.xxxx change to any domain you want
| The code is as follows |
Copy Code |
ServerName www.111cn.net |
#这里是你的放网址的文件夹地址 ...
| The code is as follows |
Copy Code |
DocumentRoot "d:/www/php" DirectoryIndex index.html index.htm index.php Options FollowSymLinks AllowOverride None Order Allow,deny Allow from all |
Step Three:
Search the Hosts file in C:/windows and add
127.0.0.1 www.111cn.net
Fourth Step:
Restart apache! See, configure the virtual host is so simple, these are after I personally tested, so you can rest assured that use.
Perhaps some classmates have some problems, such as I configured the above virtual host, www.111cn.net can be normal access, but http://localhost instead of hanging, can not visit. What do we do? Don't worry, a few people help you solve the problem.
The workaround is as follows:
Locate the httpd-vhosts.conf under the Conf/extra file and add a code to the last side:
| The code is as follows |
Copy Code |
ServerName http://localhost DocumentRoot "D:/www" DirectoryIndex index.html index.htm index.php Options FollowSymLinks AllowOverride None Order Allow,deny Allow from all |
Then search the Hosts file in the C:/windows, add a sentence
127.0.0.1 localhost
Restart apache!!!
Configuration methods in other operating systems
Redhat Enterprise Linux (including CentOS Linux), is the most widely used Linux server, a large number of Web applications are deployed on it.
1. Open the file/etc/httpd/conf/httpd.conf, search VirtualHost example, find the code as follows:
| The code is as follows |
Copy Code |
# # VirtualHost Example: # Almost any Apache directive could into a virtualhost container. # the ' The ' the ' the ' the ' I VirtualHost ' used for requests without a known # server name. # #<virtualhost *:80> # ServerAdmin Webmaster@dummy-host.example.com # documentroot/www/docs/dummy-host.example.com # ServerName Dummy-host.example.com # ErrorLog Logs/dummy-host.example.com-error_log # Customlog Logs/dummy-host.example.com-access_log Common #</virtualhost>
|
2. Follow the example, add a section of code to specify a domain name site.
| The code is as follows |
Copy Code |
# # DocumentRoot is the root directory of Web site files # ServerName is the website domain name, needs to be consistent with DNS point domain name # <virtualhost *:80> ServerAdmin webmaster@dummy-host.example.com Documentroot/var/www/httpdocs/demo_neoease_com ServerName demo.neoease.com ErrorLog Logs/demo.neoease.com-error.log Customlog Logs/demo.neoease.com-access.log Common </VirtualHost>
|
3. Restart the httpd service and execute the following statement.
| The code is as follows |
Copy Code |
Service httpd Restart |
Ubuntu Linux
Ubuntu has the largest number of individual users in Linux distributions. Many people use it in both native and virtual machines. However, the VirtualHost settings for Ubuntu and Redhat are not the same.
1. Open the directory/etc/apache2/sites-available/, found the default and Default-ssl two files, where default is the HTTP virtual Host service configuration file, DEFAULT-SSL is configured HTTPS The service is used. You can copy a default file. and modify the configuration file name, the filename must be consistent with the domain name (such as: demo.neoease.com)
2. Open the new configuration file, modify DocumentRoot, ServerName, and the corresponding configuration directory. Examples are as follows:
| The code is as follows |
Copy Code |
# # DocumentRoot is the root directory of Web site files # ServerName is the website domain name, needs to be consistent with DNS point domain name # <virtualhost *:80> ServerAdmin webmaster@dummy-host.example.com Documentroot/var/www/httpdocs/demo_neoease_com ServerName demo.neoease.com ErrorLog ${apache_log_dir}/demo.neoease.com-error.log Customlog ${apache_log_dir}/demo.neoease.com-access.log combined </VirtualHost>
|
3. Activate the virtual host configuration via A2ensite
| The code is as follows |
Copy Code |
sudo a2ensite demo.neoease.com
|
4. Open the directory/etc/apache2/sites-enabled/, you will find all activated virtual host, can be logged out via A2dissite
| The code is as follows |
Copy Code |
sudo a2dissite demo.neoease.com
|
5. Restart the Apache service and activate the virtual host
| The code is as follows |
Copy Code |
Sudo/etc/init.d/apache2 restart
|
Windows
Windows is the most market-share PC operating system and is also a development environment for many people. Its VirtualHost configuration method differs from Linux in that it is suitable for native Apache, XAMPP, and WAMP kits in the following ways.
1. Open the directory {Apache2 installation directory}confextra to locate the httpd-vhosts.conf file.
2. Follow the example, add a section of code to specify a domain name site.
| The code is as follows |
Copy Code |
# # DocumentRoot is the root directory of Web site files # ServerName is the website domain name, needs to be consistent with DNS point domain name # <virtualhost *:80> ServerAdmin webmaster@dummy-host.example.com DocumentRoot "D:/workspace/php/demo_neoease_com" ServerName demo.neoease.com ErrorLog "Logs/demo.neoease.com-error.log" Customlog "Logs/demo.neoease.com-access.log" common </VirtualHost>
|
3. Open the httpd.conf file and add the following statement.
| The code is as follows |
Copy Code |
# Virtual Hosts Include conf/extra/httpd-vhosts.conf
|
4. Restart the Apache service.