Implementation of virtual domain names in Linux (2)

Source: Internet
Author: User


At present, the Linux operating system is very popular, so many friends want to know about the implementation process of virtual domain names in Linux. Next we will discuss it based on the popular RedHat.
Ii. Apache server configuration

Apache server is currently the most widely used Web server on the Internet. It can maintain very busy sites. RedHat 6.0 is bound with Apache Web Server 1.3. Its configuration file is located in the "/etc/httpd/conf" directory, including httpd. conf, SRM. conf, and access. conf. The following describes the configurations related to virtual domain names:

1. Static Configuration

To modify the configuration file httpd. conf:

(1) first set UseCanonicalName to off. It indicates that the servername value is provided to the environment variable SERVER_NAME by replacing the server host: header content.

(2) then add:

Namevirtualhost XXX. XXX is the IP address of the virtual server to be configured. Multiple virtual IP addresses can be configured here, which must be consistent with those configured on the DNS server. (Note: The IP address must be used here, and the domain name cannot be used .)

(3) Add a record for each virtual domain name:

<Virtualhost XXX. XXX>
.....
</Virtualhost>

XXX. XXX must be the same as the IP address configured for namevirtualhost. The following configuration parameters can be added between two flags:

The virtual domain name to be added after servername, such as aaa.domain.com;
DocumentRoot: add the path mapped to the local machine, for example, "/home/AAA ";
Redirect: If you map a URL to the remote end, it can be added to the backend. There are two parameters: the first is the relative path of the virtual domain name, and the second is the URL of the remote site;
After serveralias, you can add an alias for this domain name. Wildcards can be used, such as * .aaa.domain.com.

The following are two examples:

Example 3: physical path mapped to the local machine:

<Virtualhost XXX. XXX>
DocumentRoot "/home/test"
Servername test.domain.com
<Virtualhost>
Example 4: URL mapped to the remote end:

<Virtualhost XXX. XXX>
Servername test1.doamin.com
Redirect/http://test.domain1.com/welcome.htm
</Virtualhost>

There are also some parameters, such as the location of the log file, timeout settings, buffer settings, and so on. For details here, refer to the online help file of the Apache server. After the httpd. conf file is configured, restart the Apache background daemon httpd,

[Root @ domain/root] #/etc/rc. d/init. d/httpd restart

Each time a virtual domain name is added, a configuration item located between <virtualhost...>... </virtualhost> is added.CodeAnd the new configuration takes effect only after httpd is restarted.

2. dynamic configuration

It can be found that if you want to configure a large number of virtual domain names, the length of the configuration file will be greatly increased, which will also slow Apache startup, occupy more memory, and it is not easy to implement online application. You can select Dynamic Mode for configuration. In this way, you do not have to write the configuration in advance, but write dynamic rules to automatically generate or read information from an independent configuration file at any time.

Apache has a powerful extension function, namely the module feature. The module can expand the functions of the server, which is loaded into the server only during running and use, thus saving memory space and calling external CGI.ProgramFast.

Now we use a powerful module to dynamically configure virtual domain names, which is mod_rewrite. It is responsible for listening to the URL address sent from the client and rewriting the URL based on a set of rule expressions. This is similar to the concept of URL alias, but it goes further. The output URL can be mapped to any URL address of other hosts. To modify the configuration file httpd. conf:

(1) set UseCanonicalName to off first.

(2) Use rewriteengine on to open the rewrite engine. Use rewritemap to set the location and properties of the configuration file, and use rewritecond and rewriterule to create corresponding rules.

Example 5: An Example of configuration in the httpd. conf file:

Rewriteengine on
Rewritemap lowercase INT: tolower
# Define the location of an independent configuration file
Rewritemap vhost DBM:/www/CONF/vhostdbm
# Using an independent configuration file to remap virtual domain names
Rewritecond $ {vhost: % 1} ^ (/. *) $
Rewriterule ^/(. *) $ % 1/docs/$1

Rewritecond % {request_uri} ^/cgi-bin/
Rewritecond $ {lowercase: % {SERVER_NAME} ^ (. +) $
Rewritecond $ {vhost: % 1} ^ (/. *) $
Rewriterule ^/(. *) $ % 1/cgi-bin/$1

For the vhostdbm file format, see "CGI program compilation ". (Source: pconline)

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.