In-depth analysis of Apache server virtual host Setting Technology

Source: Internet
Author: User
Article Title: in-depth analysis of Apache server virtual host setting technology. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.

A www server VM is a WWW server that uses a physical machine to act as multiple host names. The advantage of using WWW Virtual Hosts is that some small-scale websites share the same physical machine with other websites, which can reduce system operation costs and reduce management difficulty. In addition, for individual users, you can also use this virtual host method to create a WWW server with its own independent domain name. Next, I will introduce how to set up various virtual hosts under Apache.

1. Introduction to Apache WWW Server

Apache WWW server is currently the most widely used WWW server software on the Internet. With flexible configuration, it can complete almost all the functions you want.

Ii. IP address-based VM settings for Apache WWW Server

To use this virtual host method, you must first set an IP address for each virtual host on the server. These IP addresses can be completed by adding multiple NICs or setting up multiple IP addresses on one Nic. With multiple IP addresses, you can set Apache in either of the following ways:

1. Run an Apache copy for each VM

In this way, each Apache program can be run by a single user, so each virtual host does not affect each other. When setting such a VM, you only need to set a configuration file for each Apache copy. The only thing you need to note is that you must use the "Listen" statement, each copy of Apache is forced to receive service requests only on its own IP address.

Advantage: each virtual host does not interfere with each other, and the security is high.

Disadvantage: it occupies a large amount of system resources.

2. Multiple virtual hosts share the same Apache

In this way, each virtual host shares the same Apache, so there is a certain impact between each virtual host, especially when executing CGI programs, it may bring some serious security problems. When setting such a VM, you only need to set the following information for each VM:

VirtualHost www.company1.com;

DocumentRoot/home/company1

...

/VirrualHost;

Advantage: less system resources are occupied than the previous method.

Disadvantage: low security. Each virtual host still needs one IP address.

Iii. Simple name-based VM settings on the Apache WWW Server

In this way, each virtual host shares the same Apache. Therefore, when a CGI program is running, the security is not high. When setting this type of virtual host, you only need to set the following information for each Virtual Host:

NameVirtualHost 111.222.33.44; receives services from the VM at this IP address.

VirtualHost 111.222.33.44;

ServerName www.company1.com

DocumentRoot/www/company1

/VirtualHost;

VirtualHost 111.222.33.44;

ServerName www.company2.com

DocumentRoot/www/company2

/VirtualHost;

Advantage: A single IP Address can provide a large number of VM services.

Disadvantage: poor security. To maintain these virtual hosts, you must change the configuration file and restart the Apache process. Therefore, it is not suitable for large-scale VM services.

4. Name-based large-scale VM settings under the Apache WWW Server

A large-scale VM is a virtual host service that can provide a large number of VM services, such as a service that can provide more than 100,000 domain names. If you use the methods discussed above, it is very difficult to complete. One way to implement this service is to use the powerful URL rewriting feature of Apache. This method is described in the following example.

1. URL rewriting in Apache

Apache 1.2 and later versions have the URL rewriting (Rewrite) function. Simply put, the URL rewriting function is to modify the URL in the request according to the preset rules after Apache receives the request. These rules are mainly composed of regular expressions. Rewriting relies on the input URL, various server-side environment variables, content in the HTTP request header, and time. You can even use external programs to use the information in the database to help rewrite.

URL rewriting is very powerful. Through URL rewriting, Apache can perform exceptionally complex functions. Of course, the URL rewriting function is also complicated. For details about the URL rewriting function, see the Apache random document.

A www server VM is a WWW server that uses a physical machine to act as multiple host names. The advantage of using WWW Virtual Hosts is that some small-scale websites share the same physical machine with other websites, which can reduce system operation costs and reduce management difficulty. In addition, for individual users, you can also use this virtual host method to create a WWW server with its own independent domain name. Next, I will introduce how to set up various virtual hosts under Apache.

Related Article

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.