Web Server - University of Victoria

Download Report

Transcript Web Server - University of Victoria

Content Serving
Static vs. Dynamic Content
Web Servers
Server Flow Control
Rev. 2.0
©2006
Scott Miller, University of Victoria
1
4/3/2016
Static vs. Dynamic Content

Static Content: Content that only changes when
the site administrator changes it
– Web pages, CSS, frame based sites, etc.
– Includes “Dynamic looking” sites that have JavaScript
client-side handlers

Dynamic Content: Customized content based on
user input
– May be input from older session (via cookies)
– Query data, DB lookups, Preferences (portal), Secure
logins for commerce, etc.
– Generated via Web Application
©2006
Scott Miller, University of Victoria
2
4/3/2016
Static vs. Dynamic Content

Web Server: Program (daemon) that listens for
HTTP requests (on port 80)
– Serves static HTML documents

File on a file system mapped to the server’s root
– Calls Application Server as needed

Application Server:
– Program called upon by a Web Server
– Dynamically generates predefined content as its
output

©2006
HTML, XHTML, ASCII, etc.
Scott Miller, University of Victoria
3
4/3/2016
Web Server – Little Bit ‘o
Practical

Domains are simply directory structures
“mapped” off the hard disk.
http://www.foo.org/
* cgi-bin would not be found!
cgi-bin
/
img
Hard drive
web
note
©2006
Scott Miller, University of Victoria
4
4/3/2016
Web Server – Little Bit ‘o
Practical

Virtual Hosting – The Web Server is
configured to read a different directory
structure as a domain’s root.
http://www.tim.biz/
http://www.ryan.biz/
ryan
/
img
Hard drive
tim
note
©2006
Scott Miller, University of Victoria
5
4/3/2016
Get to know your UNIX!

*NIX permissions are an effective shield
against content others shouldn’t have.
– Resources posted, but not yet available to user
Know your directory structure for web
serving (know what structure you will use
to host site(s) and where to locate it/them.
 Know how to edit remotely via command
line – especially know basic vi.

©2006
Scott Miller, University of Victoria
6
4/3/2016
Client-Server Web Server
Interaction
stdin
CGI
Request
HTTP
Web
Server
HTTP
Response
HTML, text, Java, etc.
©2006
Scott Miller, University of Victoria
App
Server
CGI
stdout
HTML, text, Java, etc.
7
4/3/2016
Web Server Content
HTML, CSS, XHTML, etc.
 Binary files (any binaries to be
downloaded)
 Java Applets
 JavaScript enabled content
 Media rendering directly from MIME
Types

©2006
Scott Miller, University of Victoria
8
4/3/2016
Bandwidth management

Client side scripting:
– ex. Text viewer (zoomed in) for visually
impaired

Let them scroll around and zoom on client side
after getting document from server
Caching: Only get a resource if it has
changed
 Compression: Transmit less bits through
compression

©2006
Scott Miller, University of Victoria
9
4/3/2016
Dynamic Content Serving
CGI
Rev 2.0
©2006
Scott Miller, University of Victoria
10
4/3/2016
Application Servers

If a Web Server only hosts static content,
how do we get dynamic content?
– APPLICATION SERVER!
Usually a plug-in to a web server; still a distinct
program
 Communicates with web server to perform
calculations or action and return result
 Can consist of any language

©2006
Scott Miller, University of Victoria
11
4/3/2016
Server-Server communications
stdin
CGI
Request
HTTP
Web
Server
HTTP
Response
HTML, text, Java, etc.
©2006
Scott Miller, University of Victoria
App
Server
CGI
stdout
HTML, text, Java, etc.
12
4/3/2016
CGI – Common Gateway
Interface

CGI is a protocol
– Can be written in any language that can read
from stdin, write to stdout and can read
environment variables


TRANSLATION: Pretty much any language you
like
Referenced in url
– e.g. As a directory  /cgi-bin/

Launched from web server as a separate
process to handle the request
©2006
Scott Miller, University of Victoria
13
4/3/2016
CGI Protocol

How does web server pass information to
the application server?
– Environment variables
– stdin/stdout

CGI is about sending back the “Request
Context” to the application server
– HTTP request
– HTTP headers
– parameters
©2006
Scott Miller, University of Victoria
14
4/3/2016
CGI Protocol – HTTP Headers
©2006
HTTP Header
Environment Variable
Content-Length
CONTENT_LENGTH
Content-Type
CONTENT_TYPE
User-Agent
HTTP_USER_AGENT
Host
HTTP_HOST
*
HTTP_*
Scott Miller, University of Victoria
15
4/3/2016
CGI Protocol- Example
GET /cgi-bin/Login.pl?username=Scott&pwd=foo HTTP/1.1
Host: www.uvic.ca
Cookie: loginAttempt=3
Cookie: config=1
<\r\n>
Env. Variable
HTTP_Host
Value
www.uvic.ca
QUERY_STRING
username=Scott&pwd=foo
HTTP_COOKIE
loginAttempt=3;config=1
©2006
Scott Miller, University of Victoria
16
4/3/2016
CGI Protocol – Continued

The body of a HTTP request is written to
stdin of the CGI process
– POST method: body contains the query
parameters

THEREFORE: CGI script must look
query parameters in 2 places
– If GET: QUERY_STRING
– If POST: stdin will contain
CONTENT_LENGTH bytes
©2006
Scott Miller, University of Victoria
17
4/3/2016
CGI Protocol – Finishing
Touches

The CGI program writes the full HTTP
response to stdout
– Includes HTTP headers
– In Other Words: Output of CGI program is a
complete HTTP response
©2006
Scott Miller, University of Victoria
18
4/3/2016
CGI Calling

Each CGI process is created from scratch
by the web server for each request
– Environment variables are ONLY for one
request
– CGI process terminates once it is done writing
output
©2006
Scott Miller, University of Victoria
19
4/3/2016
CG-I-Don’t-Know-About-This…

Having to output raw HTML in CGI
programs is:
1. A maintenance nightmare!!!
2. No separation of content from presentation
– 1 & 2 distinguish this approach as terrible
Software Engineering. Why?

Doesn’t scale well
–
©2006
New process for EACH request
Scott Miller, University of Victoria
20
4/3/2016
CGI Key Ideas
Output of CGI is HTML to be displayed
on the browser
 What HTML contains is determined when
the program runs (DYNAMIC
CONTENT) as a function of query
parameters
 In practice: the strings of HTML your CGI
program generates will contain variables
populated by queries

©2006
Scott Miller, University of Victoria
21
4/3/2016