How Web Servers Work |
|
Have you ever wondered
about the mechanisms that delivered this page to you? Chances are you are
sitting at a computer right now, viewing this page in a browser -- so when you
clicked on the link for this page, or typed in its URL (Uniform Resource
Locator), what happened behind the scenes to bring this page onto your
screen? If you've ever been curious about the process, or have ever wanted to
know some of the specific mechanisms that allow you to surf the Internet,
then this edition of How Stuff
Works will be a real eye opener for you. You will learn about the
Internet, and how Web browsers and Web servers use it to bring pages into
your home, school or office. Let's get started! The Basic
Process At the most basic level possible, the
following diagram shows the steps that brought that page to your screen: Your browser formed a connection to a Web
server, requested a page and received it. If you want to get into a bit more
detail, here are the basic steps that occurred behind the scenes:
If you've never explored
this process before, that's a lot of new vocabulary. To understand this whole
process in detail, you need to learn about IP addresses, ports, protocols,
etc. The following articles will lead you through a complete explanation. How the
Internet Works ISPs then connect to larger ISPs, and the
largest ISPs maintain fiber-optic "backbones" for an entire nation
or region. Backbones around the world are connected through fiber-optic lines,
undersea cables or satellite links (see this
page for a nice backbone and connection diagram). In this way, every
computer on the Internet is connected to every other computer on the Internet.
Clients and
Servers A server machine may provide one or more
services on the Internet. For example, a server machine might have software
running on it that allows it to act as a Web server, an e-mail server and an
FTP server. Clients that come to a server machine do so with a specific
intent, so clients direct their requests to a specific software server
running on the overall server machine. For example, if you are running a Web
browser on your machine, it will most likely want to talk to the Web server
on the server machine. Your telnet application will want to talk to the telnet
server, your e-mail application will talk to the e-mail server, and so on... How IP
Addresses Work 216.27.61.137
The four numbers in an IP address are called octets,
because they can have values between 0 and 255, which is 28
possibilities per octet. Every machine on the Internet has a unique IP
address. A server has a static IP address that does not change very often. A
home machine that is dialing up through a modem often has an IP address that
is assigned by the ISP when you dial in. That IP address is unique for your
session -- it may be different the next time you dial in. This way, an ISP
only needs one IP address for each modem it supports, rather than for each
customer. If you are working on a Windows machine, you can
view a lot of the Internet information for your machine, including your
current IP address and hostname, with the command IPCONFIG/ALL. On a
UNIX machine, type nslookup at the command prompt, along with a
machine name, like www.howstuffworks.com -- e.g. "nslookup
www.howstuffworks.com" -- to display the IP address of the machine, and
you can use the command hostname to learn the name of your machine.
[For more information on IP addresses see IANA]
As far as the Internet's machines are concerned, an
IP address is all you need to talk to a server. For example, in your browser
you can type the URL http://216.27.61.137 and you will arrive at the
machine that contains the Web server for How Stuff Works. On some servers,
the IP address alone is not sufficient, but on most large servers it is --
see next article
for details. How Name Servers Work The name www.howstuffworks.com actually has 3
parts:
Domain names are managed by a company called Network
Solutions. Network Solutions' primary job is to create the top-level
domain names, and to guarantee that all names within a top-level domain are
unique. Network Solutions also maintains contact information for each site
and runs the "whois" database. The host name is created by the
company hosting the domain. "www" is a very common host name, but
many places now either omit it or replace it with a different host name that
indicates a specific area of the site. For example, in encarta.msn.com,
the domain name for Microsoft's Encarta encyclopedia, "encarta" is
designated as the host name instead of "www."
A set of servers called Domain Name Servers (DNS)
maps the human-readable names to the IP addresses. These servers are simple
databases that map names to IP addresses, and they are distributed all over
the Internet. Most individual companies, ISPs and universities maintain small
name servers to map host names to IP addresses. There are also central name
servers that use data supplied by Network Solutions to map domain names to IP
addresses. If you type the URL http://www.howstuffworks.com/web-server.htm
into your browser, your browser extracts the name
"www.howstuffworks.com", passes it to a Domain Name Server, and the
Domain Name Server returns the correct IP address for www.howstuffworks.com.
A number of name servers may be involved to get the right IP address. For
example, in the case of www.howstuffworks.com, the name server for the
"com" top-level domain will know the IP address for the name server
that knows host names, and a separate query to that name server, operated by
HSW's ISP, may deliver the actual IP address for HSW's server machine. On a UNIX machine you can access the same service
using the nslookup
command. Simply type a name like "www.howstuffworks.com" into the
command, and the command will query the name servers and deliver the
corresponding IP address to you. So here it is: The Internet is made up of millions
of machines, each with a unique IP address. Many of these machines are server
machines meaning that they provide services to other machines on the
Internet. You have heard of many of these servers: e-mail servers, Web
servers, FTP servers, Gopher servers and telnet servers, to name a few. All
of these are provided by server machines. How Ports Work Each of the most well-known services is available
at a "well-known port number." Here are some common port numbers:
If the server machine accepts connections on a port
from the outside world, and if a firewall is not
protecting the port, you can connect to the port from anywhere on the
Internet and use the service. Note that there is nothing that forces, for
example, a Web server to be on port 80. If you were to set up your own
machine and load Web server software on it, you could put the Web server on
port 918, or any other unused port, if you wanted to. Then, if your machine
were known as xxx.yyy.com, someone on the Internet could connect to your
server with the URL http://xxx.yyy.com:918. The ":918"
explicitly specifies the port number, and would have to be included for
someone to reach your server. When no port is specified, the browser simply
assumes that the server is using the well-known port 80. How Protocols Work %telnet web67.ntx.net 13 Trying 216.27.61.137... Connected to web67.ntx.net. Escape character is '^]'. Sun Oct 25 08:34:06 1998 Connection closed by foreign host.
On a Windows machine, you can access this server by
typing "telnet web67.ntx.net 13" at the MSDOS prompt. In this example, web67.ntx.net is the server's UNIX
machine, and 13 is the port number for the daytime service. The telnet
application connects to port 13 (telnet naturally connects to port 23, but
you can direct it to connect to any port), then the server sends the date and
time and disconnects. Most versions of telnet allow you to specify a port
number, so you can try this using whatever version of telnet you have
available on your machine. Most protocols are more involved than daytime and
are specified in Request for Comment (RFC) documents that are publicly
available (see http://www.howstuffworks.com/framed.htm?parent=web-server.htm&url=http://sunsite.auc.dk/RFC/
for a nice archive of all RFCs). Every Web server on the Internet conforms to
the HTTP protocol, summarized nicely in this article.
The most basic form of the protocol understood by an HTTP server involves
just one command: GET. If you connect to a server that understands the HTTP
protocol and tell it to "GET filename", the server will respond by
sending you the contents of the named file and then disconnecting. Here's a typical
session: %telnet www.howstuffworks.com 80 Trying 216.27.61.137... Connected to howstuffworks.com. Escape character is '^]'. GET http://www.howstuffworks.com/ <html> <head> <title>Welcome to How Stuff Works</title> ... </body> </html> Connection closed by foreign host.
In the original HTTP protocol, all you would have
sent was the actual filename like "/" or
"/web-server.htm". The protocol was later modified to handle the
sending of the complete URL. This has allowed companies that host virtual
domains, where many domains live on a single machine, to use one IP
address for all of the domains they host. It turns out that hundreds of
domains are hosted on 216.27.61.137 -- HSW's IP address. Putting It All Together
How a Web Server Works Most servers add some level of security to the
serving process. For example, if you have ever gone to a Web page and had the
browser pop up a dialog box asking for your name and password, you have
encountered a password-protected page. The server lets the owner of the page
maintain a list of names and passwords for those people who are allowed to
access the page; the server lets only those people who know the proper
password to see the page. More advanced servers add further security to allow
an encrypted connection between server and browser, so that sensitive
information like credit card numbers can be sent on the Internet. That's really all there is to a Web server that
delivers standard "static" pages. "Static" pages are
those that do not change unless the creator edits the page. But what about the web pages that are
"dynamic"? For example:
|
Note: This
document is from howstuffworks site. Here it is used for educational purposes.
All rights are reserved with related site.