Apache Virtual Host VirtualHost configuration

Source: Internet
Author: User

Virtual Host is a technology that builds multiple Web services on the same machine that belong to different domain names or based on different IP. You can refer to different IP and ports for each Web site running on the same physical machine, or you can have multiple sites with different domain names.

Apache is the world's most widely used WEB server, starting with version 1.1 to support virtual hosting. This article will explain the use of Apache to build virtual hosts on different servers (Redhat Enterprise Linux, Ubuntu Linux, Windows) to build multiple websites.

Thrust

The purpose of this article is to let readers know how to build multiple websites on the same machine with some usage tips. Operation-oriented, not too much to talk about the principle.

Goal

This article is written to a site owner, website developer, and network administrator who has certain server configuration and management skills that need to maintain multiple sites at the same time. If you are an internet company piping engineer, familiar with the principle and operation of computer server, please ignore this article, you will not find too many valuable things.

The following are the configuration methods for each operating system.

    • Redhat Enterprise Linux
    • Ubuntu Linux
    • Windows
    • Mac OS
Redhat Enterprise Linux

Redhat Enterprise Linux (including CentOS Linux) is the most widely used Linux server, and a large number of Web applications are deployed on it.

1. Open the file/etc/httpd/conf/httpd.conf, search for VirtualHost example, find the following code:

# # VirtualHost example:# almost any Apache directive may go to a VirtualHost container.# the first VirtualHost section I s used for requests without a known# server name.##<virtualhost *:80># ServerAdmin    [email protected]#    docum entroot/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. In the example, add a piece of code to specify a domain name for the site.

# # DocumentRoot is the root directory of Web site files # ServerName is a website domain name that needs to be consistent with DNS-directed domain name #<virtualhost *:80>    ServerAdmin [email protected ]    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.

Service httpd Restart
Ubuntu Linux

Ubuntu has the largest number of individual users in Linux distributions. Many people are used in native and virtual machines. However, Ubuntu and Redhat VirtualHost are not set up in the same way.

1. Open Directory/etc/apache2/sites-available/, find the default and Default-ssl two files, where default is the HTTP virtual Host service configuration file, Default-ssl is the configuration https Used by the service. A copy of the default file can be copied. and modify the configuration file name, the file name must match the domain name (for example: demo.neoease.com)

2. Open the newly created configuration file, modify the DocumentRoot, ServerName, and the corresponding configuration directory. Examples are as follows:

# # DocumentRoot is the root directory of Web site files # ServerName is a website domain name that needs to be consistent with DNS-directed domain name #<virtualhost *:80>    ServerAdmin [email protected ]    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. Activating the virtual host configuration via A2ensite

sudo a2ensite demo.neoease.com

4. Open Directory/etc/apache2/sites-enabled/, you will find all active virtual hosts, can be logged off via A2dissite

sudo a2dissite demo.neoease.com

5. Restart the Apache service to activate the virtual host

Sudo/etc/init.d/apache2 restart
Windows

Windows is the most market-share PC operating system and a development environment for many people. The VirtualHost configuration method is somewhat different from Linux and is suitable for native Apache, XAMPP, and WAMP kits.

1. Open the directory {Apache2 installation directory}\conf\extra\, locate the httpd-vhosts.conf file.

2. In the example, add a piece of code to specify a domain name for the site.

# # DocumentRoot is the root directory of Web site files # ServerName is a website domain name that needs to be consistent with DNS-directed domain name #<virtualhost *:80>    ServerAdmin [email protected ]    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.

# Virtual Hostsinclude conf/extra/httpd-vhosts.conf

4. Restart the Apache service.

Mac OS

In recent years, Apple's rise, so that Mac day to popularize, but also become a lot of developers choice. Because of the same origin as Linux, the configuration method is similar.

1. Open the file/private/etc/apache2/extra/httpd-vhosts.conf.

2. In the example, add a piece of code to specify a domain name for the site.

# # DocumentRoot is the root directory of Web site files # ServerName is a website domain name that needs to be consistent with DNS-directed domain name #<virtualhost *:80>    ServerAdmin [email protected ]    documentroot "/usr/docs/httpdocs/demo_neoease_com"    ServerName demo.neoease.com    errorlog "/private/ Var/log/apache2/demo.neoease.com-error_log "    Customlog"/private/var/log/apache2/demo.neoease.com-access_log "Common</virtualhost>

3. Open the file/private/etc/apache2/httpd.conf, search for Virtual hosts and find the following code:

# Virtual Hosts#include/private/etc/apache2/extra/httpd-vhosts.conf

Remove the previous comment symbol # and save the file.

4. Restart the Apache service and execute the following statement.

Sudoapachectl restart
Summarize

I recently set up some Web services on several different servers, this article is also my personal notes, I hope to be able to use it later, but also want to be useful to the reader. This article describes several major development and deployment environments to configure the virtual host, the other OS is similar.

Apache Virtual Host VirtualHost configuration

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.