Apache 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.

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_aliluna_com    ServerName demo.aliluna.com    errorlog logs/ Demo.aliluna.com-error.log    customlog Logs/demo.aliluna.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.aliluna.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_aliluna_com    ServerName demo.aliluna.com    errorlog ${apache_log_ Dir}/demo.aliluna.com-error.log    customlog ${apache_log_dir}/demo.aliluna.com-access.log combined</ Virtualhost>

3. Activating the virtual host configuration via A2ensite

sudo a2ensite demo.aliluna.com

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

sudo a2dissite demo.aliluna.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_aliluna_com"    ServerName demo.aliluna.com    errorlog "logs/ Demo.aliluna.com-error.log "    customlog" Logs/demo.aliluna.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.

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 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.