Implementation of virtual domain names in Linux (2)

Source: Internet
Author: User
Article title: implementation of virtual domain names in Linux (2 ). 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.
Author: Zheng Tao/ASPCool
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 added virtual domain name requires a piece of configuration code located between <VirtualHost...>... </VirtualHost>, and the new configuration takes effect only after the 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. this saves memory space and is faster than calling an external CGI program.
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 ".
  
  
  
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.