Basic Web Server Operation

hipshorseheadsΔιακομιστές

17 Νοε 2013 (πριν από 3 χρόνια και 11 μήνες)

110 εμφανίσεις

EG
-
259 Web Applications Technology

Basic Web Server Operation


Dr C. P. Jobling
(C.P.Jobling@Swansea.ac.uk)

Part 3: Server
-
Side Programming


Basic Web Server Operation


Interactive Services


The Ruby Programming Language


Ruby on Rails


RESTful

Web Services


Datastorage

and the Cloud




Basic Web Server Operation


The roles of a web server and web client


Modern Web Servers


The Apache Web Server


Revision of the Hypertext Transfer Protocol


Web server operation


Mapping resources to files

EG
-
259 Web Applications Technology

The Role of a Web Server

A web server has only one role


respond

to a client
request
.


Client Request

The web server takes a client
request

and
gives something back to the client.


Browser

requests a
resource
.


Server

receives the request


Server

finds the
resource
(or not
)


Server

returns
something

to the client.

A resource

can be


an HTML page


A CSS file


A JavaScript


A PDF file


A picture


A fragment of XML


A sound or video file


Some JSON data


….

Server Response

The

response

is formatted as a header,
with
success code
and other information,
followed by the resource data.


A
content
-
type field

in the header
informs the client how the resource data
is to be interpreted.


If the resource is not found, server issues
a “
404 not found
” response.

The Role of a Web Client


The web client is more “intelligent” than the
web server


The web client (browser) lets the user
request

something from the server and shows the
result

of the request.


The client, by means of JavaScript, is capable
of additional manipulation of resource data
independently of the server.


The “Brains” of the Operation

Image Source: BBC: http
://
bbc.in
/
YcpNAE

Talks net protocols

Structured

Stylish

Programmable

Interacts with humans

Ubiquitous

Basic Web Server Operation


The roles of a web server and web client


Modern Web Servers


The Apache Web Server


Revision of the Hypertext Transfer Protocol
(HTTP)


Web server operation


Mapping resources to files

Modern Web Servers

Server Share Statistics (August 1995 to March
2013)


Source:
http://
news.netcraft.com
/


Some Important Web Servers

Apache Web Server (more later)

Microsoft Internet Information Service
(IIS)


Standard on windows professional


Windows only


Standard web services (files and CGI)


ASP technology provides server scripting in
multiple languages


FrontPage server extensions


Key component of .NET

Apache Tomcat


A web server written in Java


Runs on any platform that supports Java


Standard web services (files and CGI)


A “servlet container” which uses Java as a web
application programming language and Java
Server Pages (JSP) for interactivity.


Key component of J2EE.

NGINX


A webserver that is designed to handle large
numbers of simultaneous requests


Uses an event driven architecture rather than
spawning a new thread per connection.


Allows popular websites to cope with large
loads with predictable memory requirements.


Powers
Wordpress,com
,
github.com
,
sourceforge

etc.


More at:
http://wiki.nginx.org/Main


Basic Web Server Operation


The roles of a web server and web client


Modern Web Servers


The Apache Web Server


Revision of the
HyperText

Transfer Protocol
(HTTP)


Web server operation


Mapping resources to files


Apache Web Server (history)

The very first web server was built by Tim
Berners
-
Lee at CERN
circa
1989

Apache Web Server (history)


First really popular web server was
developed by NCSA and was available to all

Apache Web Server (history)



Apache was originally developed as a bug
-
fixed (“patched”) version of the NCSA Web
Server version 1.3

First release 1995

Apache Web Server (history)





Apache is open source and is developed
and maintained by a group of volunteers

Apache Web Server (history)


Apache is the most popular web server in use
today (55% of the market, 102 Million active
sites)

Program called
httpd

and runs on most common
platforms

Latest version 2.24

Some features of Apache

Efficient: efficient at serving files, low impact on
host.

Some features of Apache

Easy to set up for basic web services: files, SSI
and CGI


Just put files into “
document root
” or “
cgi
-
bin

and they are “
on the web


Some features of Apache

Extensible and modular: base services
extensible by use of modules, e.g.


For authentication


For authorization


For session management


For logging


“In memory” server scripting:
mod_perl
,
mod_python
, PHP, FrontPage server extensions, …
even ASP!.

Some features of Apache

Flexible

-

not just a web server


can be a proxy server


web cache


enables virtual hosting,
etc

Some features of Apache

Installed on the EG
-
259 Virtual Machine

Basic Web Server Operation


The roles of a web server and web client


Modern Web Servers


Introducing the Apache Web Server


Revision of the
HyperText

Transfer Protocol
(HTTP)


Web server operation


Mapping resources to files


HTTP request message


Two types of HTTP messages:
request
,
response


HTTP request message:


ASCII (human
-
readable format)

GET /somedir/page.html HTTP/1.1

Host: www.someschool.edu

User
-
agent: Mozilla/4.0

Connection: close

Accept
-
language:fr


(extra carriage return, line feed)


request line

(GET, POST,

HEAD commands)

header


lines

Carriage return,

line feed

indicates end

of message

HTTP
messages

Only two types of HTTP messages:


HTTP request


HTTP response

HTTP
Request

HTTP request message:


ASCII (human
-
readable format)

GET /
somedir
/
page.html

HTTP/1.1

Host:
www.someschool.edu


User
-
agent: Mozilla/4.0

Connection: close

Accept
-
language:fr



(extra carriage return, line feed)


request line

(GET, POST,

HEAD
commands)

header


lines

Carriage return,

line feed

indicates end

of message

HTTP response message

HTTP/1.1 200 OK

Connection close

Date: Thu, 06 Aug 1998 12:00:15 GMT

Server: Apache/1.3.0 (Unix)

Last
-
Modified: Mon, 22 Jun 1998 …...

Content
-
Length: 6821

Content
-
Type: text/html



data data data data data ...


status line

(protocol

status code

status phrase)

header


lines

data, e.g.,

requested

HTML file

HTTP response status codes

200 OK

request succeeded, requested object later in this message

301 Moved Permanently

requested object moved, new location specified later in this message
(Location:)

400 Bad Request

request message not understood by server

404 Not Found

requested document not found on this server

505 HTTP Version Not Supported

In first line in server
-
>client response message. Some examples:

HTTP request message

GET /products/ HTTP/1.1

Host: mycompany.com

User
-
agent: Mozilla/4.0

:

Accept
-
language:fr


(extra carriage return, line feed)


request line

(GET, POST,

HEAD commands)

header


lines

Carriage return,

line feed

indicates end

of message

More about Host later

Content negotiation

Client information

URI

Protocol version

HTTP response message

HTTP/1.1 200 OK

:

Date: Thu, 06 Aug 1998 12:00:15 GMT

Server: Apache/1.3.0 (Unix)

Last
-
Modified: Mon, 22 Jun 1998 …...

Content
-
Length: 6821

Content
-
Type: text/html



data data data data data ...

status line

(protocol

status code

status phrase)

header


lines

data, e.g.,

requested

HTML file

Server information

Describes data:
helps browser to
render data

Helps browser

To cache data

Size of content

in bytes

Some Important Definitions

URI (uniform resource identifier)


Format
<
protocol
>://<
host
>/<
resource
>


Uniquely identifies a resource on the Internet


Example:
http://
mycompany.com
/products/

Some Important Definitions

Resource Identifier (RI)


Uniquely identifies a resource on a host


Maps either to a file or to a program


Example:
/products/

Some Important Definitions

Content
-
Type


Identifies the type of data contained in a response


Used by the browser to render the data content of
a response


Uses MIME standard specifications


Examples:
text/html,

image/jpeg
,
application/
pdf
.

Some Important Definitions

Host


Identifies host to which request is directed. Allows
many web hosts to exist at a single IP address.


Basic Web Server Operation


The roles of a web server and web client


Modern Web Servers


The Apache Web Server


Revision of the
HyperText

Transfer Protocol
(HTTP)


Web server operation


Mapping resources to files


Web Server Operation

User types URL into browser or

clicks on a hyperlink. E.g.

http://mycompany.com/products/

<html>

<html>

<html>

server

user

browser

files

Web Server Operation

Browser opens a TCP connection to server



requires DNS query to map hostname

to IP address.



three
-
way handshake with web server process

listening on port 80

<html>

<html>

<html>

server

user

browser

files

Web Server Operation

Browser creates and sends GET request



actually sent with final acknowledgement

that establishes the TCP connection

<html>

<html>

<html>

server

user

browser

files

GET /products/ HTTP/1.1

Host:
mycompany.com

<html>

index.html

Web Server Operation

Server interprets GET request



Host

field used to identify virtual host


URI
/products/

identifies resource


index.html

in directory identified by

/products


<html>

<html>

<html>

server

user

browser

files

GET /products/ HTTP/1.1

Host:
mycompany.com

Web Server Operation

Server creates a response message



response code + content
-
type


Resource added to response

<html>

<html>

<html>

server

user

browser

files



<html>

index.html

HTTP/1.1 200 OK

:

Content
-
Type: text/html


Web Server Operation

Server returns response to client

<html>

<html>

<html>

server

user

browser

files



<html>

index.html

HTTP/1.1 200 OK

:

Content
-
Type: text/html


Web Server Operation

Browser parses response


Notes that content
-
type is HTML


Renders HTML in browser…


Makes further requests for embedded objects

<html>

<html>

<html>

server

user

browser

files



<html>

index.html

HTTP/1.1 200 OK

:

Content
-
Type: text/html


GET …

HTTP 1.1 200 OK

Content
-
type: image/jpeg

Web Server Operation

Web server returns a response even if it

cannot satisfy the request.

<html>

<html>

<html>

server

user

browser

files

HTTP/1.1 404 Not found

Web Server Operation

When page is rendered browser closes TCP

connection

<html>

<html>

<html>

server

user

browser

files

Web Server Operation

Server waits for next request

<html>

<html>

<html>

server

user

browser

files

Basic Web Server Operation


The roles of a web server and web client


Modern Web Servers


Introducing the Apache Web Server


Revision of the
HyperText

Transfer Protocol
(HTTP)


Web server operation


Mapping resources to files


How RI
/products/

Maps to a
File

/

is a special location on the web server


It is set using
DocumentRoot

directive


Physically, it is a directory e.g.

/
var
/www

A Typical Web Server

<html>

<html>

PDF

<html>

<html>

DocumentRoot

products

people

index.html

cto.html

index.html

index.html

widget.jpeg

catalogue.pdf

Homework Problems


Web server shown on previous slide is
mycompany.com
.


DocumentRoot

is
/
var
/www



Give the full URL for each file on this web server.


Give the actual file name of each resource
(directories are not resources)


Which file is
mycompany.com
’s

home page?


Find out how Apache knows how to package a
PDF file as
Content
-
type:
application/
pdf

Summary of this Lecture


The roles of a web server and web client


Modern Web Servers


Introducing the Apache Web Server


Revision of the
HyperText

Transfer Protocol
(HTTP)


Web server operation


Mapping resources to files

Further Reading

For more information on Application Protocols see:


Chapter 2 of
Kurose and Ross
.

For more information on web servers and Apache
see:


Apache: The Definitive Guide

(3
rd

Ed.), Ben Laurie
and Peter Laurie, O’Reilly, 2003.


Webmaster in a Nutshell

(3
rd

Ed.), Stephen
Spainhour

and Robert Eckstein, O’Reilly, 2003.

For more information on web client technology


Web Design in a Nutshell

(3
rd

Ed.), Jennifer
Niederst

Robbins, O’Reilly, 2006.



In EG
-
253 You Gained Experience of


Apache configuration


Real HTTP requests and responses


Server directives


Setting up a basic web server


You may wish to review the notes!

Next Lecture


Interactive Services


Server
-
Side Includes


CGI


Server
-
side scripting


REST