How to develop a virtual domain name system. It is very convenient for everyone to use a simple domain name such as yourname.yeah.net. many people are wondering: if I can enable my server to implement a simple domain name. In fact, it is very convenient for everyone to use a simple domain name such as yourname.yeah.net. many people are wondering: if I can enable my server to implement a simple domain name, I would be fine. In fact, this is not complicated. After reading this article, you can also create a simple domain name system.
The key technology of the simplified domain name system is to achieve Redirctory on the web page ). In essence, the domain name system is completely different from the virtual machine system. There is a one-to-one correspondence between virtual domain names and IP addresses of virtual machines. The simplified domain name system does not need to map domain names and IP addresses one by one. That is to say, it does not need complicated domain name resolution mechanisms or virtual machines. what it does is when you request yourname. in somedomain, redirect your browser to the place where you originally stored the Html page.
The following figure shows a better description:
The source program I provided is the runtime environment: Apache1.3.6 Web Server + PHP3 in RedHat 5.1 Linux. Before writing a program, we must first set up our server. First, let the Apache server support php3. Go to ftp.redhat.com to download the mod_php-2.0.1-9.i386.rpm. after installing, modify/etc/httpd/conf/http. in the conf file, remove the # Comment # in front of the # LoadModule php3_module statement, also in/etc/httpd/conf/srm. remove # AddType application/x-httpd-php3 in the conf file. comment number before php3, and add index after DirectoryIndex. php3. Restart Apache Server. now the Server supports standard php3 script files and uses index. php3 as the default homepage.
Set the DNS server so that it can resolve wildcard domain names. Generally, DNS resolution for Unix and Linux systems is completed by the Bind daemon. the Bind4 and Bind8 configuration files are/etc/named respectively. boot and name. conf, which is modified according to your system. Set the Bind configuration file/etc/named. boot, add "primary domain.com db. domain" to add a new domain record. Add the following to/etc/name. conf:
Zone "domain.com "{
Type master;
File "db. domain ";
};
Create the master domain record file db. domain in/var/name/in the format:
N soa dns.domain.com root.domain.com (
199811291; Serial
28800; refresh
7200; retry
604800; expire
86400); minimum
Dns
MX 10 dns.domain.com.
Dns A 202.115.135.50
Www A 202.115.135.50
* A 202.115.135.50
The key is the last sentence, that is, all hostnames not marked in the entire domain may point to the same IP address. Run/usr/sbin/ndc reload to reload the domain name database. In this test, you should ping a host in the domain (except the host that has been marked) and point to the specified IP address. then, the DNS server settings are complete.
The last step is to compile the PHP3 script. We have already explained the entire principle in detail in the figure, so it is not difficult to write a retargeting program.
Let's take a look at the complete HTTP header information sent by IE5.0:
Accept: application/vnd. ms-excel, application/msword, application/vnd. ms-powerpoint, image/gif, image/x-xbitmap, image/jpeg, image/pjpeg ,*/*
Accept-Encoding: gzip, deflate
Accept-Language: zh-cn
Connection: Keep-Alive
Host: ww.yahoo.com
User-Agent: Mozilla/4.0 (compatible; MSIE 5.0b1; Windows 98)
We need to retrieve the Host information from the entire HTTP header, and then retrieve the first packet in the form of http://www.jj.jx.cn/www.xxx.xxx/default.htm, that is, the hostname (also the name registered by the user) separately as the keyword for redirect retrieval.
After retrieving the URL information registered by the user, we will send a redirection command "Localtion: http://www.jj.jx.cn/somewhere/sample.html#to redirect the user to the specified page.
In PHP3, the GetAllHeader () function is provided to obtain the HTTP header information sent by the browser. We mainly need to use this function to complete the entire program.
The source program is appended. because it is only experimental, the database is not used when querying user information. if the entire system needs to be applied, it must be linked to the database, otherwise, the process of querying user information will be very long, greatly affecting the efficiency, and the management of user data is not convenient. (Due to space limitations, the write record program required for registration and management is not provided. please add it as needed)
In the source program, all user information is recorded in the user. dat file under the data subdirectory. The format is:
Username:
Http://octopus.cdit.edu.cn /~ Qap213/index.html
Appendix PHP3 source code:
// Get HTTP's Header and parse it //
$ Headers = getallheaders ();
While (list ($ header, $ value) = each ($ headers )){
If ($ header = "Host") {$ username = strtok ($ value ,".");}}
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.