Configure Apache Virtual Host VirtualHost in Linux

Source: Internet
Author: User
VirtualHost is a technology used to build multiple website services with different domain names or based on different IP addresses on the same machine. you can specify different IP addresses and ports for each website running on the same physical machine, or assign different domain names to multiple websites. apache is the most widely used Web server in the world. It has supported virtual hosts since version 1.1. this article will explain how to RedHatEnterpriseLinux

Virtual Host)It is a technology for building multiple website services with different domain names or based on different IP addresses on the same machine. you can specify different IP addresses and ports for each website running on the same physical machine, or assign different domain names to multiple websites.

Apache is the most widely used Web server in the world. It has supported virtual hosts since version 1.1. this article will explain how to use Apache to build virtual hosts on different servers (RedHat Enterprise Linux, Ubuntu Linux, and Windows) to build multiple websites.

Theme

This article aims to let readers know how to build multiple websites on the same machine with some usage skills. It focuses on operations and won't talk too much about the principles.

Target

This article is intended for website owners, website developers, and network administrators who have certain server configuration and management skills and need to maintain multiple websites at the same time. if you are a pipe engineer in an Internet company and are very familiar with the principles and operations of computer servers, please ignore this article and you will not find too many valuable things on it.

Redhat Enterprise Linux

Redhat Enterprise Linux (including CentOS Linux) is the most widely used Linux server. A large number of website applications are deployed on it.

1. open the file/etc/httpd/conf/httpd. conf, search for VirtualHost example, and find the Code as follows:

12345678910111213
## VirtualHost example:# Almost any Apache directive may go into a VirtualHost container.# The first VirtualHost section is used for requests without a known# server name.##
     
      #    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#
     

2. Add a piece of code to specify the website of a domain name.

1234567891011
# DocumentRoot is the root directory for storing website files # ServerName is the website domain name, which must be consistent with the domain name pointed to by DNS #
     
      
ServerAdmin zhao.wuz@alibaba-inc.com 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
     

3. Restart the httpd service and execute the following statement.

1
service httpd restart
Ubuntu Linux

Ubuntu has the largest number of individual users in various Linux releases. Many of them are used in the local and virtual machines. However, the VirtualHost setting methods for Ubuntu and Redhat are different.

1. open the/etc/apache2/sites-available/directory and find the default and default-ssl files. default is the configuration file of the http VM service, default-ssl is used to configure the https service. you can copy a default file. and modify the configuration file name. The file name must be consistent with the domain name (for example, demo.aliluna.com)

2. Open the new configuration file and modify DocumentRoot, ServerName, and the corresponding configuration directory. The example is as follows:

1234567891011
# DocumentRoot is the root directory for storing website files # ServerName is the website domain name, which must be consistent with the domain name pointed to by DNS #
     
      
ServerAdmin zhao.wuz@alibaba-inc.com DocumentRoot/var/www/httpdocs/demo_aliluna_com ServerName assumerrorlog $ {APACHE_LOG_DIR}/your-error. log CustomLog $ {APACHE_LOG_DIR}/your-access. log combined
     

3. Activate the virtual host configuration through a2ensite

1
sudo a2ensite demo.aliluna.com

4. Open the/etc/apache2/sites-enabled/directory, and you will find that all activated virtual hosts can be logged out through a2dissite.

1
sudo a2dissite demo.aliluna.com

5. Restart the Apache service and activate the VM.

1
sudo /etc/init.d/apache2 restart
Windows

Windows is the PC operating system with the highest market share and is also the development environment for many people. Its VirtualHost configuration method is somewhat different from that on Linux. The following methods are suitable for native Apache, XAMPP, and WAMP suites.

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

2. Add a piece of code to specify the website of a domain name.

1234567891011
# DocumentRoot is the root directory for storing website files # ServerName is the website domain name, which must be consistent with the domain name pointed to by DNS #
     
      
ServerAdmin zhao.wuz@alibaba-inc.com DocumentRoot "D:/workspace/php/demo_aliluna_com" ServerName demo.aliluna.com ErrorLog "logs/logs-error. log" CustomLog "logs/demo.aliluna.com-access. log" common
     

3. Restart the Apache service.

Summary

Recently, I have set up some website services on several different servers. This article is my personal note. I hope it will be useful to readers. this article describes how to configure virtual hosts in several mainstream development and deployment environments. Other operating systems are similar.

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.