Up until this point in the book, you have been opening web pages in the browser directly from the file system. Obviously, if you intend your web pages to be viewed by others, you need to make them available over a network. The software used for exposing web pages over a network is a web server.
The term “web server” can either denote the hardware of the underlying server or the software running on that server. For the purposes of this lesson, the term “web server” will be used to denote the software, whereas “server” will be used to denote the hardware this software runs on.
The primary purpose of a web server is to expose a set of resources from the file system of a network enabled server via protocols such as HTTP and HTTPS. Resources are typically files such as HTML pages, images, and CSS files, to video and audio files.
In this lesson, you will migrate the web application developed so far to a web server. You are doing this for two main reasons:
Before looking at web servers, this chapter will quickly cover the related topic of URLs (Uniform Resource Locators). A URL provides a unique network address for a resource (image, web page, CSS file). The “network” will often be the public Internet, but URLs can also be used to locate resources on private networks, such as your personal WiFi network at home.
The web server is responsible for parsing the URL and determining the resource that should be returned. The URL is also used by lower-level protocols, however, to determine how to route the request to the appropriate server on the network.
URLs are surprisingly complex, but the most familiar pattern is as follows:
http://testing.com:80/test1/test.html
This URL consists of the following components:
http
: The protocol that is being used to access the resource; other common protocols are https
and ftp
.testing.com
: The domain name resolved by the browser to an IP address using a Domain Name Server (DNS). The IP address (for instance 192.168.199.133) in turn maps to a server running on a network.80
: The port number of the web server. Because a single server may expose multiple services (for example, an FTP server and an HTTP server), port numbers provide a mechanism to logically differentiate them. You will not usually see the port number in URLs because 80 is the default for the HTTP protocol, and 443 is the default for the HTTPS protocol, and the port number can therefore usually be omitted.test1
: The directory on the web server. Typically, the web server will map its root directory to a directory on the file system. In this case, there would be an assumption that this directory contains a subdirectory called test1
.test.html
: The name of the resource being accessed.The two most important components used by the APIs in this section are the domain name and the port. These are referred to as the “origin” of a resource. Typically, a resource will only be able to interact with resources or information from the same origin: This is referred to as the same origin policy.
There are many web servers available, both commercial and open source. Many factors come into play when choosing a web server, but these discussions are beyond the scope of this book. It is, however, worth mentioning that by far the most popular web server, almost since the advent of the World Wide Web, is the Apache web server.
Apache is an open source web server, and provides an excellent combination of stability, features, and performance. If you use a hosting service, they will almost certainly make the Apache web server available to you.
You will not use Apache in this book, mainly because it takes slightly more effort to install and configure than the web server you will use, but you may opt to use it if you choose. It can be accessed from http://httpd.apache.org/
, and tutorials are available for guiding you through the installation and configuration process.
In this book, you will use the Mongoose web server (free edition). The main reason for choosing this is its simplicity: It requires either very little or no configuration and is therefore ideal during the development phase of your web application.
In this Try It, you install and configure the Mongoose web server. This Try It contains two sets of steps, one for Windows and one for OS X.
As part of the steps outlined next, you will need to download the Mongoose web server from the site listed. This will involve agreeing to the non–commercial license agreement. You will also need the Chrome web browser to test that the web server is working.
http://cesanta.com/downloads.html
. This requires you to accept the license agreement.document_root
text field, and change the directory to the directory that contains the contacts.html
file. For example /Users/dane/html5/CRM
. Once entered, click “Save settings to the config file”.localhost
. Therefore, to open the contacts page, open Chrome, and enter http://localhost:8080/contacts.html. This should show the main contacts web page.http://cesanta.com/downloads.html
. This requires you to accept the license agreement..exe
file to the same directory that contains contacts.html
.localhost
. Therefore, to open the contacts page, open Chrome, and enter http://localhost:8080/contacts.html.This should show the main contacts web page.
18.118.208.97