Implement Virtual Domain Name

Source: Internet
Author: User
Tags subdomain
 
Implement Virtual Domain Name
 
     

Complete virtual domain name implementation requires three conditions:
1. DNS server wildcard domain name resolution settings; 2. Web Server wildcard domain name binding settings; 3. browser support (more than 3.0 support); the three conditions are met, then, on the VM, use the virtual domain name CGI program to implement a virtual domain name like my.yeah.net.

The following article introduces the implementation methods of NT and Unix respectively. Implementation of virtual domain names under NT -- posting-Feiyun ethereal 08-19-2000

A virtual domain name is actually a type of virtual host. The emergence of virtual hosts is to save hardware investment. If the ISP uses a single machine for each user who applies for a domain name, the cost is obviously high, and it is also a waste for sites that are not frequently accessed. As a result, everyone has a public machine, but each user is independent of each other, and its function is completely equivalent to having its own host.

There are two types of virtual hosts: IP-based and name-based. Although the IP address-based VM is deployed on the same machine, you still need to configure an independent IP address for each domain name. This does not seem to be an ideal solution. Can I use a machine, an IP address, and an independent domain name?

This idea has been implemented with the emergence of HTTP/1.1 protocol. The principle is that web servers and browsers work together to map a virtual domain name to a corresponding directory or site. In this way, users enter different names in the browser. Although the DNS server resolves the same IP address, the obtained content is different. It looks like two independent domain names. Therefore, this name-based virtual host is also called non-IP (non-IP ). This also provides a useful way to give a long URL a memorable and meaningful alias. This is the virtual domain name.

Virtual domain names must be supported in two aspects:

First, Web servers: Many Web servers now support name-based virtual hosts. Such as Netscape and IIS. Of course, the most commonly used is Apache Web Server. The reason is that it is easy to configure and free, and it is the first server product that implements a name-based virtual host.

Second, users' browsers: I think most of them should be IE or Netscape of version 3.0 or later, so there is no problem. They all support it. Let's take a look at how to implement a virtual domain name in NT:

The first step is to ask the DNS server to know the domain name you want to add, that is, to interpret it as the corresponding IP address. Because we rely on Web servers to differentiate domain names, this IP address is naturally managed by your web server.

All you need to do is add an alias record in the DNS service. If you want to add aaa.domain.com and want to point to www.domain.com, you can write AAA in cname www.domain.com.

Maybe you will think that if I want to add a lot of domain names, it will not be very troublesome, and the record files on the DNS server will be very large. Okay. Let's lie to the DNS server and change "AAA" to "*". In this way, all records ending with domain.com that have not been set will be transferred to www.domain.com, whether it is aaa.domain.com or bbb.domain.com. This does not affect existing records.

The next step is to configure the web server. We select two common ones: IIS and Apache for NT.

1. IIS (remember that name-based virtual hosts are supported only for Versions later than 4.0 .)

Enter the IIS Service Manager, select Add web site on the corresponding server, give the site a name, and select the IP address (that is, the previously set DNS server points ). Select the main directory path. If it is mapped to a remote URL, you can set a temporary path first.

After the web site is created, click "Advanced..." in the "web site" tab... "button, edit the ID record, and fill in the virtual domain name to be added in" host title name ", for example, aaa.domain.com. Remember to fill in the complete field, and do not open AAA. Now, you can select the specific directory to be mapped in the "main directory" label. It can be the path on the local machine or the local machine, or the URL of the remote site.

IIS configuration is intuitive, but it is not suitable for online applications if there are a large number of records.

2. Apache (the new version has started to support NT, you can go to the http://www.apache.org to get the latest version, and with source code, interested can develop some new features)

To configure Apache, you need to deal with the configuration file HTTP. conf. It is located in the Apache/conf directory by default.

First, add namevirtualhost XXX. XXX to the IP address of your virtual server, that is, the IP address of www.domain.com in the preceding example. You can configure multiple virtual IP addresses here. (Note: IP addresses are used here, rather than domain names)

Next, add a record for each virtual domain name :...... XXX. XXX must be consistent with 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 adds the path mapped to the local machine to the backend, for example, "F:/html/AAA" (double quotation marks are required). Redirect adds the path mapped to the remote URL 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 the alias of this domain name. Wildcards can be used, such as * .aaa.domain.com.

The following are examples: 1. Physical paths mapped to the local machine: DocumentRoot "F:/program files/Apache Group/Apache/htdocs/test" servername test.domain.com 2. ing to a remote URL: Servername test1.doamin.com redirect/http://test.domain1.com/welcome.htm of course there are many parameters, such as the location of the log file, timeout settings, buffer settings and so on, you can refer to the Apache online help file. Each time a virtual domain name is added Configuration code between... and takes effect only after Apache is restarted.

Obviously, if you want to configure a large number of records, 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 configure the VM dynamically. 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. This requires the mod_rewrite module of Apache. Therefore, add loadmodule rewrite_module modules/apachemodulerewrite. DLL to the configuration file.

You can develop many rules to rewrite URLs, such as maintaining URLs through environment variables, HTTP headers, or even external databases. Its functions are very powerful, which also brings complexity. you have to constantly explore and experiment to grasp it, but this is worth it.

Finally, we will briefly introduce one of the implementations of online free Domain Names: 1. Maintain a user database through Perl, and manage user addition, deletion, verification, and password change. 2. At the same time, Perl is used to maintain independent virtual domain name configuration files through the database, such as: vdomains. MAP, the format is as follows: aaa.domain.com http://www.domain1.com /~ AAA bbb.domain.com http://www.domain2.com /~ Bbb...

3. Configure the httpd. conf file. Use rewriteengine on to open the rewrite module, use rewritemap to set the location and properties of the configuration file, and use rewritecond and rewriterule to create corresponding rules.

Configure the DNS server for virtual domain names in Linux

We know that the Internet is based on the TCP/IP protocol, and the IP address of the other party must be obtained for communication. This is achieved through the DNS server. Therefore, to implement a virtual domain name, the DNS server should first accept the virtual domain name, that is, map it to the specified IP address. Because we rely on Web servers to differentiate domain names, this IP address should naturally be managed by Web servers.

The bind dns server is bound to the redhat6.0 operating system. Its Domain Name configuration file is "/etc/named. conf". Generally, the domain configuration file is placed under the "/var/named" directory. Named. CONF file configuration: Zone "domain.com" {type master; file "domain.com" ;}; zone "0.10.10.in-ADDR. ARPA "{type master; file" 10.10.0 ";};

This example shows that the domain configuration file of "domain.com" is "/var/named/domain.com", and the reverse domain configuration file is "/var/named/10.10.0 ". The domain.com file maps the DNS domain name to an IP address. 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

Assume that the domain name to be added is aaa.domain.com. To name www.domain.com, add an alias record to the DNS service and write it as AAA in cname www.domain.com. if you need to configure a large number of virtual domain names, the domain.com file is very large and troublesome. We can use the symbol "*" to add * In cname www.domain.com to the domain.com file.

In this way, all records ending with domain.com that have not been set are transferred to www.domain.com, whether aaa.domain.com or bbb.domain.com. This does not affect existing records. After the DNS server is configured, restart the daemon named: [root @ domain/root] #/etc/rc. d/init. d/named restart.

-------------------------------------------------------------------------

The configuration of the 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. modify the configuration file httpd. conf in static configuration: (1) set UseCanonicalName to off first. It indicates that the servername value is provided to the environment variable SERVER_NAME by replacing the server host: header content. (2) 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 is used here, and the domain name is not used .) (3) Add a record for each virtual domain name: ... XXX. XXX must be consistent with 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, for example, aaa.domain.com. If you map DocumentRoot to the local machine, add the following configuration parameters, for example, "/home/AAA"; Redirect: If the URL you map to the remote end can be added to the backend, there are two parameters. The first one is the relative path of the virtual domain name, 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 paths mapped to the local machine: DocumentRoot "/home/test" servername test.domain.com Example 4. ing to a remote URL: Servername test1.doamin.com redirect/http://test.domain1.com/welcome.htm also has some parameters, such as the location of the log file, timeout settings, buffer settings and so on, here is not a one-to-one introduction, you can refer to the Apache server online help file. Configure httpd. after the conf file, restart the Apache background daemon httpd, [root @ domain/root] #/etc/rc. d/init. d/httpd restart Configuration code between... and takes effect only after httpd is restarted.

2. dynamic configuration 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 and occupy more memory, it is not easy to apply online. 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, 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. httpd. example of related configuration in the conf file: rewriteengine on rewritemap lowercase INT: tolower # define the location of the independent configuration file rewritemap vhost DBM: /www/CONF/vhostdbm # use an independent configuration file to remap the virtual domain name 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 preparation ".

-------------------------------------------------------------------------------

To implement online application for a virtual domain name, you must write the corresponding CGI program to dynamically modify the independent configuration file (that is, the preceding vhostdbm file) and manage users (including user application, logon, password modification, and so on ). This section only describes operations on independent configuration files. For more information about how to write CGI programs in Perl, see.

The vhostdbm file uses the DBM format to record data. Compared with common text files, the file search speed is faster and easier to modify. Many Unix systems have a standard library called database management. This database stores a set of key-value pairs in a pair of disk files. It provides a simple database management tool to conveniently change, add, or delete data content.

Perl accesses dBm by connecting the associated array to the DBM database through a process similar to opening a file. When a new element is created in the array, the DBM database is changed immediately. Deleting an element also deletes the values in the DBM database. Available:

1. to associate a dBm database with a dBm array: dbmopen (% arrayname, "dbmfilename", $ mode); Create a database if dbmfilename does not exist. The % arrayname parameter is an associated array of Perl (if the array already has values, these values will be deleted ). The joined array is connected to the DBM database called dbmfilename. $ Mode is the number used to control the permission of the database file when a database needs to be created. This number is specified as an octal value, and 0644 is often used, read-Only permissions are granted to new users except the host. The host has all permissions.

2. Disable the DBM Database: dbmclose (% arrayname); % arrayname is the array name associated with the DBM database. Example 6. open vhostdbm with vhost, or create a new dBm Database: dbmopen (% vhost, "vhostdbm", 0644); example 7. create a record or change an existing record (set the parameter names from the HTML file form to vhost and rHost ): $ vhost {$ FORM {'vhost' }}=$ FORM {'rhost'}; Example 8. delete an existing record (the parameter name passed from the form in the HTML file is vhost): delete $ vhost {$ FORM {'vhost'}; Example 9. disable vhostdbm: dbmclose (% vhost). Note: If the parameter passed in has been verified, no duplicate records exist. Otherwise, the existing records may be disordered.

Wildcard domain name resolution-NT

Wildcard domain name resolution refers to the process of creating a domain, for example, creating an abc.com domain, and configuring how to resolve any xxx.abc.com domain to an address, this problem has been solved in service pack4 (because it is very easy to implement on UNIX), but it is not actually solved. After Microsoft's SP6a was released, the problem was solved and the configuration was quite easy. Related: http://download.microsoft.com/download/winntsp/Install/6.0a/NT4/CN/SP6I386.EXE

If this patch is installed on NT4.0, the problem can be easily solved. Open the DNS manager, create the abc.com domain, create a record (host record) in the domain, enter * in the host name, and add the corresponding address. b. c. d. In this way, any xxx.abc.com will be resolved to address. b. c. d. Of course, there will be no problems in parsing specific host records.

Can be tested: xxx.chinaasp.org, the primary DNS Server responsible for resolution: ns.chinasp.com (202.101.18.171) Scud

Create a subdomain named * in the current domain, and create a host with an empty Host name in the subdomain.

Example of wildcard domain name settings in Unix/Linux

1. DNS: ...... @ in a 202.11.11.11 * in a 202.11.11.11 ...... Apache: ................. Serveralias yourname.net www.yourname.net serveralias www.yourname.net * .yourname.net servername www.yourname.net ................. you can change the IP address and domain name to your own one.

2. Apache: ................. Servername www.yourname.net serveralias yourname.net www.yourname.net * .yourname.net .................

The above article from: http://www.coolwww.net

Virtual domain CGI program: http://www.coolwww.net/cgi/free.htm

Here there is another CGI program implementation method: http://cgi.chinalb.com/http://cgi.chinalb.com/write/1-4.htm

 

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.