Implementation of virtual domain name under Linux (2) _unix Linux

Source: Internet
Author: User
Tags lowercase

Currently Linux operating system is very hot, so many friends want to know about Linux under the virtual domain name implementation process. The following is based on the current more popular Redhat to discuss. II. Configuration of Apache servers

The Apache server is the most widely used Web server on the Internet, and it can maintain very busy sites. The RedHat 6.0 bundled Apache Web Server 1.3. Its configuration file is located in the "/etc/httpd/conf" directory, there are httpd.conf, srm.conf, access.conf, the following discusses the configuration related to the virtual domain name:

1. Static configuration

To modify the configuration file httpd.conf:

(1) First set Usecanonicalname to OFF. It instructs the content of the server host:header instead of the servername value to be supplied to the environment variable server_name.

(2) then add:

Namevirtualhost xxx.xxx.xxx.xxx where xxx.xxx.xxx.xxx is the IP address of the virtual server that you want to configure. Multiple virtual IP addresses can be configured here, with the same configuration as in the DNS server. (Note: Here to use the IP address, can not use the domain name.) )

(3) Next, add a record for each virtual domain name:

< VirtualHost xxx.xxx.xxx.xxx>
.....
</virtualhost>

xxx.xxx.xxx.xxx to match the IP address configured with Namevirtualhost. The configuration parameters that can be added between two flags are:

ServerName After you want to add the virtual domain name, such as aaa.domain.com;
DocumentRoot If you map to the local path is added to the back, such as "/HOME/AAA";
redirect If you map to the remote URL can be added to the back, there are two parameters, the first is the relative path of the virtual domain name, the second is the URL of the remote site;
Serveralias can be added to the domain name alias, you can use wildcard characters, such as *.aaa.domain.com.

Here are two examples:

Example 3, the physical path mapped to this machine:

< VirtualHost xxx.xxx.xxx.xxx>
DocumentRoot "/home/test"
ServerName test.domain.com
< virtualhost> example 4, URLs mapped to the remote:

< VirtualHost xxx.xxx.xxx.xxx>
ServerName test1.doamin.com
Redirect/http://test.domain1.com/welcome.htm
</virtualhost>

There are also some parameters, such as the location of log files, timeout settings, buffer settings, and so on, this is not a description, you can refer to the Apache server online Help files. After configuring the httpd.conf file, you need to restart the Apache daemon httpd.

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

Each additional virtual domain name is added to the configuration code between the < virtualhost...>...</virtualhost>, and the new configuration will not take effect until the httpd is restarted.

2. Dynamic configuration

It can be found that if you want to configure a large number of virtual domain names will greatly increase the length of the configuration file, which will make the Apache startup slow, occupy more memory, and not easy to implement online applications. You can configure it by selecting dynamic methods. This eliminates the need to write a configuration beforehand, but by writing a certain dynamic rule to automatically generate or read information from a stand-alone configuration file at any time.

Apache has a powerful extension function, which is the feature of the module (Modules). The module can extend the function of the server, it is loaded into the server when it is run and used, which saves memory space and is faster than calling external CGI programs.

Now use a powerful module to implement dynamic configuration of virtual domain name, this is mod_rewrite. It is responsible for listening to the URL address sent out by the client and overriding the URL based on a set of rule expressions. This is similar to the URL alias concept, but it is a step further and the output URL can be mapped to any URL address of another host. 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 attributes of the configuration file, and use Rewritecond and rewriterule to make the corresponding rules.

Example 5, an example of a related configuration in the httpd.conf file:

Rewriteengine on
Rewritemap lowercase Int:tolower
# defines the location of a separate configuration file
Rewritemap Vhost dbm:/www/conf/vhostdbm
# re-map a virtual domain name with a separate configuration file
Rewritecond ${vhost:%1} ^ (/.*) $
Rewriterule ^/(. *) $%1/docs/$1

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

The vhostdbm file format is shown in the "CGI programming". (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.