Linux implementation of virtual domain



Author: Zheng Tao

Linux operating system is very hot now, so many of my friends want to know about Linux, the realization of the virtual domain. The following are based on current popular on RedHat to discuss.

1, DNS server settings

We know that the Internet network is based on TCP / IP protocol to communicate must be each other's IP address, which is achieved through the DNS server. So in order to make the virtual domain should first DNS server to accept the virtual domain, that is, it maps to the specified IP address. Because we rely on to distinguish the domain name Web server, so this should be the IP address of the natural managed Web server.

RedHat6.0 operating system bundled with BIND DNS server. It is the domain configuration file is "/ etc / named.conf", under normal circumstances, the domain configuration files in "/ var / named" directory.

Cases 1, named.conf configuration file:

zone "domain.com" (
type master;
file "domain.com";
);
zone "0.10.10.in-addr.arpa" (
type master;
file "10.10.0";
);

The examples of "domain.com" domain configuration file is "/ var / named / domain.com", reverse domain configuration file is "/ var/named/10.10.0". domain.com file is responsible for mapping DNS domain IP address.

Cases 2, domain.com file configuration:

@ IN SOA dns.domain.com. Hostmaster.dns.domain.com. (
1998111003; serial
3600; refresh
900; retry
1209600; expire
43200; default_ttl
)
@ IN MX 10 dns.domain.com.
@ IN NS dns.domain.com.
@ IN A 10.10.0.1
www IN A 10.10.0.1

Assumed to increase the domain name is aaa.domain.com, want to point to www.domain.com, DNS services should be added to an alias record, can be written as:

aaa IN CNAME www.domain.com.

If you need to configure a large number of virtual domain, domain.com file to be big, but also very cumbersome. We can use the symbol "*", that is, to join in the domain.com file:

* IN CNAME www.domain.com.

So that it did not put all the settings given to domain.com to www.domain.com end to all the records, and whether aaa.domain.com or bbb.domain.com. This will not affect the existing record. Configured DNS server should restart the daemon named:

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




[Next]



Linux operating system is very hot now, so many of my friends want to know about Linux, the realization of the virtual domain. The following are based on current popular on RedHat to discuss.

2, Apache server configuration

Apache server is the most widely used Internet Web server, which can maintain a very busy site. RedHat 6.0 bundles the Apache Web Server 1.3. Its configuration file located in "/ etc / httpd / conf" directory, there are httpd.conf, srm.conf, access.conf, discuss the following relating to the configuration of the virtual domain:

1, static configuration

Steps to modify the configuration file httpd.conf:

(1) First set UseCanonicalName is off. It indicates that with the server Host: header replace the ServerName value content to provide to the environment variable SERVER_NAME.

(2) and then added:

NameVirtualHost xxx.xxx.xxx.xxx where xxx.xxx.xxx.xxx is the virtual server to configure the IP address. Here you can configure multiple virtual IP addresses, of course, with the same DNS server configuration. (Note: This use IP addresses, domain names can not be used.)

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


.....


and the NameVirtualHost xxx.xxx.xxx.xxx to the IP address of the same configuration. Between the two marks can be added to the configuration parameters are:

ServerName back with you to increase the virtual domain, such as aaa.domain.com;
Documentroot If you mapped to the path of the machine behind the increase, such as "/ home / aaa";
redirect If you map to a remote URL to add to the back, there are two parameters, the first is the virtual domain relative path, the second is the remote site URL;
ServerAlias after joining the domain alias, you can use wildcards such as *. aaa.domain.com.

The following two examples:

Example 3, mapped to the physical path of the machine:


DocumentRoot "/ home / test"
ServerName test.domain.com


Example 4, mapping to a remote URL:


ServerName test1.doamin.com
redirect / http://test.domain1.com/welcome.htm


Some parameters, such as log file location, timeout settings, buffer settings, etc., not 11 in this description can refer to the Apache server's online help files. Httpd.conf file configured to restart Apache after the background daemon httpd,

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

Each additional period to be increased in a virtual domain name in the ...< / VirtualHost> the configuration between the code, and only after you restart httpd new configuration to take effect.

2, dynamic configuration

Can be found, if you want to configure the number of virtual domain will greatly increase the length of the profile, it also make Apache start slow, take up more memory, but not easy to achieve apply online. Can choose to configure dynamically. Without the prior written this configuration, but through the preparation of certain rules to automatically generate dynamic, or at any time from the separate configuration file to read information.

Apache has a powerful extension that module (Modules) features. Module can extend the functionality of the server, and use it when running into the server, so that has been placed in the server than to save memory space, while calling the external CGI process than speed.

Now use a powerful module to dynamically configure a virtual domain, that is mod_rewrite. It is responsible for listening from the client sent the URL address and the expression based on a set of rules to be rewritten to the URL. This is similar to the concept of URL aliases, but it goes a step further, the output of the URL can be mapped to any other host URL address. Steps to modify the configuration file httpd.conf:

(1) The first set UseCanonicalName is off.

(2) the use of open rewrite engine RewriteEngine on. Set the configuration file with RewriteMap location and attributes, with RewriteCond and RewriteRule to develop the corresponding rules.

Cases 5, httpd.conf file, the configuration of an example:

RewriteEngine on
RewriteMap lowercase int: tolower
# Define a separate configuration files
RewriteMap vhost dbm: / www / conf / vhostdbm
# Use separate configuration file to map the virtual domain
RewriteCond $ (vhost:% 1) ^(/.*)$
RewriteRule ^/(.*)$% 1/docs / $ 1

RewriteCond% (REQUEST_URI) ^ / cgi-bin /
RewriteCond $ (lowercase:% (SERVER_NAME)) ^(.+)$
RewriteCond $ (vhost:% 1) ^(/.*)$
RewriteRule ^/(.*)$% 1/cgi-bin / $ 1

Here vhostdbm file format, see "CGI program preparation."




[Next]

Linux operating system is very hot now, so many of my friends want to know about Linux, the realization process of the virtual domain. The following are based on current popular on RedHat to discuss.

Third, CGI programming for

To apply online virtual domain, you must write the appropriate CGI program dynamically modify the separate configuration file (that is above vhostdbm files) and for user management (including user applications, login, password changes, etc.). This only describes the profile of independent operation, the other is how to use the Perl language to write CGI programs, please refer to the relevant information.

vhostdbm file using dbm format to record data, and compared with a plain text file can speed up the search for speed, and easy to modify. Many UNIX systems have called dbm (database management) of the standard library. The library will be key - value pairs stored to a disk file, to provide simple database management tool, you can easily change, add or delete the data content.

Perl access dbm way: open the file through a similar process of an associative array with the dbm database will be linked. Create a new element in the array immediately changed when the dbm database. Remove an element while also remove the dbm database values. Can be used:

1, wishing to dbm dbm array of databases and associated with:

dbmopen (% arrayname, "dbmfilename", $ mode);

If dbmfilename does not exist on the new library. % Arrayname parameter is Perl's associative array (if the array already has a value, then these values will be deleted). The associative array connected to the called dbmfilename the dbm database. $ Mode argument is the need to create a library when the library file permissions to control the number, the figure is designated as the 8 system, is often used is 0644, in addition to the new addition to the main machine to read-only permissions for the user, machine owners to have full access.

2, close the dbm library:

dbmclose (% arrayname);
% Arrayname dbm library is already associated with the array name.

Cases 6, VHOST open vhostdbm, or create a dbm library:

dbmopen (% VHOST, "vhostdbm", 0644);

Example 7, the new records or change existing records (located in the transfer form from the html file over the parameter named vhost, rhost):
$ VHOST ($ FORM (''vhost''}}=$ FORM (''rhost'');

Example 8, delete the existing record (set in the transfer form from the html file over the parameter named vhost):
delete $ VHOST ($ FORM (''vhost''}};

Example 9, close vhostdbm:

dbmclose (% VHOST);

Note: The above parameters have been assumed transmission over after verification, there is no repeat of the record, otherwise it will lead to chaos have been recorded.