1.4 Web Server Operation

quaggahooliganInternet και Εφαρμογές Web

5 Φεβ 2013 (πριν από 4 χρόνια και 5 μήνες)

217 εμφανίσεις

Copyright
©

2008 Pearson Education, Inc. Publishing as Pearson Addison
-
Wesley

Chapter 1

Fundamentals

1
-
2

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison
-
Wesley

1.1 A Brief Intro to the Internet


Internet History


Internet Protocols

1
-
3

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison
-
Wesley

1.1 Internet History


Origins


ARPAnet
-

late 1960s and early 1970s


Network reliability


For ARPA
-
funded research organizations


BITnet, CSnet
-

late 1970s & early 1980s


email and file transfer for other institutions


NSFnet
-

1986


Originally for non
-
DOD funded places


Initially connected five supercomputer centers


By 1990, it had replaced ARPAnet for non
-
military uses


Soon became the network for all (by the early 1990s)


NSFnet eventually became known as the Internet

1
-
4

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison
-
Wesley

1.1 Internet History


What the Internet is:


A world
-
wide network of computer networks


At the lowest level, since 1982, all connections use TCP/IP
-

Transmission Control Protocol (TCP) / Internet Protocol
(IP)


TCP/IP hides the differences among devices connected to
the Internet

1
-
5

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison
-
Wesley

1.1 Internet Protocols


Internet Protocol (IP) Addresses


Every node has a unique numeric address


Form: 32
-
bit binary number


Example: 140.126.5.8


New standard, IPv6, has 128 bits (1998)


Example: 2001:ca0:20:1b00:211:25ff:feaa:d20f/64


Organizations are assigned groups of IPs for their computers


Problem: By the mid
-
1980s, several different protocols had
been invented and were being used on the Internet, all with
different user interfaces (Telnet, FTP (File Transfer
Protocol), Usenet, mailto)

1
-
6

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison
-
Wesley

1.1 Internet Protocols


Domain names


Form: host
-
name.domain
-
names


First domain is the smallest; last is the largest


Last domain specifies the type of organization


Fully qualified domain name
-

the host name and all of the
domain names


Example: www.chu.edu.tw


DNS servers
-

convert fully qualified domain names to IPs

1
-
7

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison
-
Wesley

Client and Server


Clients and Servers are programs that communicate with
each other over the Internet


A Server runs continuously, waiting to be contacted by a
Client


Each Server provides certain services


Services include providing web pages


A Client will send a message to a Server requesting the
service provided by that server


The client will usually provide some information,
parameters, with the request

1
-
8

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison
-
Wesley

1.2 The World
-
Wide Web


A possible solution to the proliferation of different protocols
being used on the Internet


Origins


Tim Berners
-
Lee at CERN (European Organization for
Nuclear Research) proposed the Web in 1989


Purpose: to allow scientists to have access to many
databases of scientific work through their own
computers


Document form: hypertext


Pages? Documents? Resources?


We’ll call them documents


Hypermedia


more than just text


images, sound, etc.

1
-
9

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison
-
Wesley

1.2 The World
-
Wide Web


Web or Internet?


The Web uses one of the protocols, HTTP, that runs on
the Internet
-

there are several others (telnet, mailto, etc.)


HTTP: Hypertext Transfer Protocol (HTTP) is a
communications protocol used to transfer or convey
information on the World Wide Web.

1
-
10

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison
-
Wesley

1.3 Web Browsers


Browsers are clients
-

always initiate, servers react (although
sometimes servers require responses)


Mosaic
-

NCSA (Univ. of Illinois), in early 1993


First to use a GUI, led to explosion of Web use


Initially for X
-
Windows, under UNIX, but was ported to
other platforms by late 1993


Most requests are for existing documents, using HyperText
Transfer Protocol (HTTP)


But some requests are for program execution, with the
output being returned as a document

1
-
11

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison
-
Wesley

1.4 Web Servers


Provide responses to browser requests, either existing
documents or dynamically built documents


Browser
-
server connection is now maintained through more
than one request
-
response cycle


All communications between browsers and servers use
Hypertext Transfer Protocol (HTTP)

1
-
12

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison
-
Wesley

1.4 Web Server Operation


Web servers run as background processes in the operating
system


Monitor a communications port on the host, accepting
HTTP messages when they appear


All current Web servers came from either

1.
The original from CERN

2.
The second one, from NCSA

1
-
13

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison
-
Wesley

1.4 Web Server Operation Details


Web servers have two main directories:

1.
Document root (servable documents)

2.
Server root (server system software)


Document root is accessed indirectly by clients


Its actual location is set by the server configuration file


Requests are mapped to the actual location


Virtual document trees: Document trees that are formed by
document collection stored outside the directory of document
root and can be accessed from the document root.


1
-
14

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison
-
Wesley

1.4 Web Server Operation Details


Virtual hosts: Multiple web host names can serve on the
same web server.


Proxy servers: a server which services the requests of its
clients by forwarding requests to other servers.


Web servers also support other Internet protocols


1
-
15

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison
-
Wesley

1.4 Web Server Operation : Apache


Apache (open source, fast, reliable)


Directives (operation control):

ServerName: server name

ServerRoot: path to server system software

ServerAdmin: email of the administrator

DocumentRoot: path to servable document root

Alias: mapping from the actual path to the virtual path of
the document

Redirect: redirect a document to other

DirectoryIndex: index.html, index.htm, index.php

UserDir: the directory for each user

1
-
16

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison
-
Wesley

1.4 Web Server Operation : Install Apache


Download Apache HTTP server (
apache_2.2.6
-
win32
-
x86
-
no_ssl.msi
) at
http://www.mirror.tw/pub/apache/httpd/binaries/win32/


Click apache_2.2.6
-
win32
-
x86
-
no_ssl.msi


Server Information


Network Domain: csie.chu.edu.tw


Server Name: Atlantis


Administrator’s Email Address:
chang@csie.chu.edu.tw


Choose
Typical

installation


Close other Web server if necessary


Start the Apache Web server


Try http://localhost


1
-
17

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison
-
Wesley

1.4 Web Server Operation : Install Apache


Open the httpd.conf file at

C:
\
Program Files
\
Apache Software Foundation
\
Apache2.2
\
conf.


ServerRoot "C:/Program Files/Apache Software
Foundation/Apache2.2 "


DocumentRoot "C:/Program Files/Apache Software
Foundation/Apache2.2/htdocs “


Create a hello.html file under the htdocs directory.

<html>

<body>

Hello, World!

</body>

</html>


Try
http://localhost/hello.html

or try http://your_ip/hello.html.

.




1
-
18

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison
-
Wesley

1.4 Web Server Operation : IIS


IIS (Internet Information Services)


Microsoft Windows IIS a set of Internet
-
based services for
servers using Microsoft Windows.


Operation is maintained through a program with a GUI
interface.


Installing IIS


To install IIS, add components, or remove components,

Click
Start
, point to
Settings
, click
Control Panel

and
start the
Add/Remove

Programs application.


Select
Configure Windows
, click the
Components

button, and then follow the on
-
screen instructions to install,
remove, or add components to IIS.


1
-
19

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison
-
Wesley

Internet Information Services 6 Console


Create a hello.html file under the C:
\
Inetpub
\
wwwroot.


Try
http://localhost/hello.html

or try http://your_ip/hello.html.

.




1
-
20

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison
-
Wesley

Internet Information Services 7 Console

1
-
21

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison
-
Wesley

1.5 URLs


General form:

scheme:object
-
address


The scheme is often a communications protocol, such as
http, telnet ,or ftp


For the http protocol, the object
-
address is: fully qualified
domain name/doc path


For the file protocol, only the doc path is needed


Example: http://www.csie.chu.edu.tw/


1
-
22

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison
-
Wesley

1.5 URLs


Host name may include a port number, as in zeppo:80 (80 is
the default, so this is silly)


URLs cannot include spaces or any of a collection of other
special characters (semicolons, colons, ...)


The doc path may be abbreviated as a partial path


The rest is furnished by the server configuration


If the doc path ends with a slash, it means it is a directory

1
-
23

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison
-
Wesley

1.6 Multipurpose Internet Mail Extensions (MIME)


Originally developed for email


Used to specify to the browser the form of a file returned by
the server (attached by the server to the beginning of the
document)


Type specifications


Form:

type/subtype


Examples: text/plain, text/html, image/gif, image/jpeg

1
-
24

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison
-
Wesley

1.6 Multipurpose Internet Mail Extensions (MIME)


Server gets type from the requested file name’s suffix (.html
implies text/html)


Browser gets the type explicitly from the server


Experimental types


Subtype begins with x
-



e.g., video/x
-
msvideo


Experimental types require the server to send a helper
application or plug
-
in so the browser can deal with the file

1
-
25

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison
-
Wesley

1.7 The HyperText Transfer Protocol


The protocol used by ALL Web communications


Request Phase


Form:

HTTP method domain part of URL HTTP ver.

Header fields

blank line

Message body


An example of the first line of a request:

GET /degrees.html HTTP/1.1

1
-
26

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison
-
Wesley

1.7 The HyperText Transfer Protocol: Methods


GET
-

Fetch a document


POST
-

Execute the document, using the data in body


HEAD
-

Fetch just the header of the document


PUT
-

Store a new document on the server


DELETE
-

Remove a document from the server

1
-
27

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison
-
Wesley

1.7 HTTP Headers


Four categories of header fields:

General, request, response, & entity


Common request fields:

Accept: text/plain

Accept: text/*

If
-
Modified_since: date


Common response fields:

Content
-
length: 488

Content
-
type: text/html

-
Can communicate with HTTP without a browser

> telnet www.csie.chu.edu.tw http

GET /respond.html HTTP/1.1

Host: www

1
-
28

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison
-
Wesley

1.7 HTTP Response


Form:

Status line

Response header fields

blank line

Response body


Status line format:

HTTP version status code explanation


Example: HTTP/1.1 200 OK

(Current version is 1.1)


Status code is a three
-
digit number; first digit specifies the general status

1 => Informational

2 => Success

3 => Redirection

4 => Client error

5 => Server error


The header field, Content
-
type, is required

1
-
29

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison
-
Wesley

1.7 HTTP Response Example

> telnet www.chu.edu.tw 80

Trying 140.126.3.102...

Connected to www.chu.edu.tw.

Escape character is '^]'.

HEAD / HTTP/1.1

host: www


HTTP/1.1 200 OK

Date: Thu, 04 Oct 2007 14:04:14 GMT

Server: Apache/2.0.52 (CentOS)

Last
-
Modified: Mon, 01 Oct 2007 03:11:55 GMT

ETag: "1f809e
-
259
-
43b65cc7814c0"

Accept
-
Ranges: bytes

Content
-
Length: 601

Connection: close

Content
-
Type: text/html

1
-
30

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison
-
Wesley

1.8 The Web Programmer’s Toolbox


Document languages and programming languages that are
the building blocks of the web and web programming


XHTML (eXtensible HyperText Markup Language)


Plug
-
ins


Filters


XML (eXtensible Markup Language)


Javascript


Java, Perl, Ruby, PHP

1
-
31

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison
-
Wesley

1.8 XHTML


To describe the general form and layout of
documents


An XHTML document is a mix of content and
controls


Controls are tags and their attributes


Tags often delimit content and specify something about
how the content should be arranged in the document


Attributes provide additional information about the content
of a tag

1
-
32

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison
-
Wesley

Creating XHTML documents


XHTML editors
-

make document creation easier


Shortcuts to typing tag names, spell
-
checker,


WYSIWYG (What You See Is What You Get)
XHTML editors


Need not know XHTML to create XHTML documents


Example: Microsoft FrontPage, Adobe Dreamweaver

1
-
33

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison
-
Wesley

1.8 Plugins and Filters


Plug ins


Integrated into tools like word processors, effectively
converting them to WYSIWYG XHTML editors


Example: Microsoft Word, Microsoft PowerPoint


Filters


Convert documents in other formats to XHTML


Example: SautinSoft RTF to XHTML Converter

1
-
34

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison
-
Wesley

1.8 Plugins and Filters: Advantages and Disadvantages


Advantages of both filters and plug
-
ins:


Existing documents produced with other tools can be
converted to XHTML documents


Use a tool you already know to produce XHTML


Disadvantages of both filters and plug
-
ins:


XHTML output of both is not perfect
-

must be fine tuned


XHTML may be non
-
standard


You have two versions of the document, which are difficult
to synchronize

1
-
35

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison
-
Wesley

1.8 XML


A meta
-
markup language


Used to create a new markup language for a particular
purpose or area


Because the tags are designed for a specific area, they can
be meaningful


No presentation details


A simple and universal way of representing data of any
textual kind

1
-
36

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison
-
Wesley

1.8 JavaScript


A client
-
side HTML
-
embedded scripting language


Only related to Java through syntax


Dynamically typed and not object
-
oriented


Provides a way to access elements of HTML documents and
dynamically change them

1
-
37

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison
-
Wesley

1.8 Java


General purpose object
-
oriented programming language


Based on C++, but simpler and safer


Our focus is on applets, servlets, and JSP

1
-
38

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison
-
Wesley

1.8 Perl


Provides server
-
side computation for HTML documents,
through CGI


CGI (Common Gateway Interface) is a standard protocol for
interfacing external application software with a web server.


Perl is good for CGI programming because:


Direct access to operating systems functions


Powerful character string pattern
-
matching operations


Access to database systems


Perl is highly platform independent, and has been ported to
all common platforms


Perl is not just for CGI

1
-
39

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison
-
Wesley

1.8 PHP


A server
-
side scripting language


An alternative to CGI


Similar to JavaScript


Great for form processing and database access through the
Web

1
-
40

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison
-
Wesley

1.8 Ruby


Ruby is an interpreted scripting language for quick and easy
object
-
oriented programming.


It has elegant syntax and readable. But it can be difficult to
understand and implement without a little help.


Ruby on Rails is a free web application framework that aims
to increase the speed and ease with which database
-
driven
web sites can be created and offers skeleton code
frameworks (scaffolding) from the outset.


1
-
41

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison
-
Wesley

1.8 Ruby on Rails


Advantages

1.
Building applications much faster because the
applications use less code, they are easier to maintain.


The internal library that Ruby on Rails has is quite
impressive.

2.
All of the functionality of RoR (Ruby on Rails) is
contained in the framework itself.


Eliminating the need for configuration.


Disadvantages


Not widely supported.


Not easy to learn



1
-
42

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison
-
Wesley

1.8 Ajax


Ajax is a web development technique used for creating
interactive web applications.


Advantages of Ajax


Reduce bandwidth usage by generating the HTML locally


Separation of data, format, style, and function


Disadvantages


Browser integration


"Back" function might not bring desired results.


Response
-
time concerns


Search engine optimization


Dynamically generated pages is not easy for search
engine optimization


Reliance on JavaScript


Not easy for Web analytics