580 likes | 973 Views
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.
E N D
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
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. • Browserrequests a resource. • Serverreceives the request • Server finds the resource (or not) • Server returns somethingto the client.
A resourcecan 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 Theresponseis 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 Talks net protocols Ubiquitous Structured Stylish Programmable Interacts with humans Image Source: BBC: http://bbc.in/YcpNAE
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
request line (GET, POST, HEAD commands) header lines Carriage return, line feed indicates end of message 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)
HTTP messages Only two types of HTTP messages: • HTTP request • HTTP response
request line (GET, POST, HEAD commands) header lines Carriage return, line feed indicates end of message 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)
status line (protocol status code status phrase) header lines data, e.g., requested HTML file 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 ...
HTTP response status codes In first line in server->client response message. Some examples: 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
Protocol version URI More about Host later request line (GET, POST, HEAD commands) Client information header lines Content negotiation Carriage return, line feed indicates end of message HTTP request message GET /products/ HTTP/1.1 Host: mycompany.com User-agent: Mozilla/4.0 : Accept-language:fr (extra carriage return, line feed)
status line (protocol status code status phrase) header lines Server information data, e.g., requested HTML file Helps browser To cache data Describes data: helps browser to render data Size of content in bytes 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 ...
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
browser <html> <html> <html> user files server Web Server Operation User types URL into browser orclicks on a hyperlink. E.g.http://mycompany.com/products/
browser <html> <html> <html> user files server Web Server Operation • Browser opens a TCP connection to server • requires DNS query to map hostnameto IP address. • three-way handshake with web server process listening on port 80
browser <html> <html> <html> user files server Web Server Operation GET /products/ HTTP/1.1Host: mycompany.com • Browser creates and sends GET request • actually sent with final acknowledgementthat establishes the TCP connection
browser <html> <html> <html> user files server index.html <html> Web Server Operation GET /products/ HTTP/1.1Host: mycompany.com • Server interprets GET request • Host field used to identify virtual host • URI /products/ identifies resource • index.html in directory identified by/products
browser <html> <html> <html> user files server index.html <html> Web Server Operation HTTP/1.1 200 OK:Content-Type: text/html • Server creates a response message • response code + content-type • Resource added to response
browser <html> <html> <html> user files server HTTP/1.1 200 OK:Content-Type: text/html index.html <html> Web Server Operation Server returns response to client
browser <html> <html> <html> user files server HTTP/1.1 200 OK:Content-Type: text/html index.html <html> Web Server Operation GET … HTTP 1.1 200 OKContent-type: image/jpeg • Browser parses response • Notes that content-type is HTML • Renders HTML in browser… • Makes further requests for embedded objects
browser <html> <html> <html> user files server Web Server Operation HTTP/1.1 404 Not found Web server returns a response even if it cannot satisfy the request.
browser <html> <html> <html> user files server Web Server Operation When page is rendered browser closes TCP connection
browser <html> <html> <html> user files server Web Server Operation Server waits for next request
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