Tải bản đầy đủ - 0 (trang)
Chapter 17. Web Servers (IIS and Apache)

Chapter 17. Web Servers (IIS and Apache)

Tải bản đầy đủ - 0trang

17.WebServers(IISandApache)

Objectives

Inthischapteryouwilllearn:

Tounderstandawebserver'sfunctionality.

TointroduceMicrosoftInternetInformationServices(IIS)

andApacheHTTPServer.

Tosetupvirtualdirectoriesfromwhichcontentcanbe

served.

Totestwhetheryousetupthevirtualdirectoryproperly.

Stopabusingmyverses,orpublishsomeofyourown.

—Martial

Therearethreedifficultiesinauthorship:towrite

anythingworththepublishing,tofindhonestmento

publishit,andtogetsensiblementoreadit.

—CharlesCalebColton

WhenyourDaemonisincharge,donottrytothink

consciously.Drift,waitandobey.

—RudyardKipling

Outline

17.1 Introduction

17.2 HTTPTransactions

17.3 MultitierApplicationArchitecture



17.4 Client-SideScriptingversusServer-SideScripting

17.5 AccessingWebServers

17.6 MicrosoftInternetInformationServices(IIS)





17.6.1 MicrosoftInternetInformationServices(IIS)

5.1and6.0







17.6.2 MicrosoftInternetInformationServices(IIS)

7.0



17.7 ApacheHTTPServer

17.8 RequestingDocuments

17.9 WebResources



17.1.Introduction

Inthischapter,wediscussthespecializedsoftware—calleda

webserver—thatrespondstoclientrequests(typicallyfroma

webbrowser)byprovidingresourcessuchasXHTML

documents.Forexample,whenusersenteraUniformResource

Locator(URL)address,suchaswww.deitel.com,intoaweb

browser,theyarerequestingaspecificdocumentfromaweb

server.ThewebservermapstheURLtoaresourceonthe

server(ortoafileontheserver'snetwork)andreturnsthe

requestedresourcetotheclient.Duringthisinteraction,the

webserverandtheclientcommunicateusingtheplatformindependentHypertextTransferProtocol(HTTP),aprotocolfor

transferringrequestsandfilesovertheInternetoralocal

intranet.

OurwebserverdiscussionintroducesMicrosoftInternet

InformationServices(IIS)andtheopensourceApache

HTTPServer.Sections17.6and17.7discussIISandApache,

respectively.



Part4:RichInternetApplicationServer

Technologies

Oneofthepowerfulthingsaboutnetworkingtechnology

liketheInternetortheWebortheSemanticWeb...is

thatthethingswe'vejustdonewiththemfarsurpass

theimaginationofthepeoplewhoinventedthem.

—TimBerners-Lee,interviewedbyPeterMoon,IDG

Now



17.WebServers(IISandApache)

Objectives

Inthischapteryouwilllearn:

Tounderstandawebserver'sfunctionality.

TointroduceMicrosoftInternetInformationServices(IIS)

andApacheHTTPServer.

Tosetupvirtualdirectoriesfromwhichcontentcanbe

served.

Totestwhetheryousetupthevirtualdirectoryproperly.

Stopabusingmyverses,orpublishsomeofyourown.

—Martial

Therearethreedifficultiesinauthorship:towrite

anythingworththepublishing,tofindhonestmento

publishit,andtogetsensiblementoreadit.

—CharlesCalebColton

WhenyourDaemonisincharge,donottrytothink

consciously.Drift,waitandobey.

—RudyardKipling

Outline

17.1 Introduction

17.2 HTTPTransactions

17.3 MultitierApplicationArchitecture



17.4 Client-SideScriptingversusServer-SideScripting

17.5 AccessingWebServers

17.6 MicrosoftInternetInformationServices(IIS)





17.6.1 MicrosoftInternetInformationServices(IIS)

5.1and6.0







17.6.2 MicrosoftInternetInformationServices(IIS)

7.0



17.7 ApacheHTTPServer

17.8 RequestingDocuments

17.9 WebResources



17.1.Introduction

Inthischapter,wediscussthespecializedsoftware—calleda

webserver—thatrespondstoclientrequests(typicallyfroma

webbrowser)byprovidingresourcessuchasXHTML

documents.Forexample,whenusersenteraUniformResource

Locator(URL)address,suchaswww.deitel.com,intoaweb

browser,theyarerequestingaspecificdocumentfromaweb

server.ThewebservermapstheURLtoaresourceonthe

server(ortoafileontheserver'snetwork)andreturnsthe

requestedresourcetotheclient.Duringthisinteraction,the

webserverandtheclientcommunicateusingtheplatformindependentHypertextTransferProtocol(HTTP),aprotocolfor

transferringrequestsandfilesovertheInternetoralocal

intranet.

OurwebserverdiscussionintroducesMicrosoftInternet

InformationServices(IIS)andtheopensourceApache

HTTPServer.Sections17.6and17.7discussIISandApache,

respectively.



17.2.HTTPTransactions

Inthissection,wediscusswhatoccursbehindthesceneswhen

auserrequestsawebpageinabrowser.TheHTTPprotocol

allowsclientsandserverstointeractandexchangeinformation

inauniformandreliablemanner.

Initssimplestform,awebpageisnothingmorethanan

XHTMLdocumentthatdescribestoawebbrowserhowto

displayandformatthedocument'sinformation.XHTML

documentsnormallycontainhyperlinksthatlinktodifferent

pagesortootherpartsofthesamepage.Whentheuserclicks

ahyperlink,therequestedwebpageloadsintotheuser'sweb

browser.Similarly,theusercantypetheaddressofapageinto

thebrowser'saddressfield.



URIs

HTTPusesURIs(UniformResourceIdentifiers)toidentifydata

ontheInternet.URIsthatspecifydocumentlocationsarecalled

URLs(UniformResourceLocators).CommonURLsrefertofiles,

directoriesorobjectsthatperformcomplextasks,suchas

databaselookupsandInternetsearches.IfyouknowtheURLof

apubliclyavailableresourceorfileanywhereontheweb,you

canaccessitthroughHTTP.



PartsofaURL

AURLcontainsinformationthatdirectsabrowsertothe

resourcethattheuserwishestoaccess.Computersthatrun

webserversoftwaremakesuchresourcesavailable.Let's

examinethecomponentsoftheURL

http://www.deitel.com/books/downloads.html

Thehttp://indicatesthattheresourceistobeobtainedusing

theHTTPprotocol.Themiddleportion,www.deitel.com,isthe

server'sfullyqualifiedhostname—thenameoftheserveron

whichtheresourceresides.Thiscomputerusuallyisreferredto



asthehost,becauseithousesandmaintainsresources.The

hostnamewww.deitel.comistranslatedintoanIPaddress—a

uniquenumericalvaluethatidentifiestheservermuchasa

telephonenumberuniquelydefinesaparticularphoneline.

MoreinformationonIPaddressesisavailableat

en.wikipedia.org/wiki/IP_address.Thistranslationis

performedbyadomainnamesystem(DNS)server—a

computerthatmaintainsadatabaseofhostnamesandtheir

correspondingIPaddresses—andtheprocessiscalledaDNS

lookup.

TheremainderoftheURL(i.e.,/books/downloads.html)

specifiesboththenameoftherequestedresource(theXHTML

documentdownloads.html)anditspath,orlocation(/books),

onthewebserver.Thepathcouldspecifythelocationofan

actualdirectoryonthewebserver'sfilesystem.Forsecurity

reasons,however,thepathnormallyspecifiesthelocationofa

virtualdirectory.Theservertranslatesthevirtualdirectory

intoareallocationontheserver(oronanothercomputeron

theserver'snetwork),thushidingthetruelocationofthe

resource.Someresourcesarecreateddynamicallyusingother

informationstoredontheservercomputer,suchasadatabase.

ThehostnameintheURLforsucharesourcespecifiesthe

correctserver;thepathandresourceinformationidentifythe

resourcewithwhichtointeracttorespondtotheclient's

request.



MakingaRequestandReceivingaResponse

WhengivenaURL,awebbrowserperformsasimpleHTTP

transactiontoretrieveanddisplaythewebpagefoundatthat

address.Figure17.1illustratesthetransaction,showingthe

interactionbetweenthewebbrowser(theclientside)andthe

webserverapplication(theserverside).

Figure17.1.Clientinteractingwithwebserver.Step1:

TheGETrequest.



[Viewfullsizeimage]



InFig.17.1,thewebbrowsersendsanHTTPrequesttothe

server.Therequest(initssimplestform)is

GET/books/downloads.htmlHTTP/1.1



ThewordGETisanHTTPmethodindicatingthattheclient

wishestoobtainaresourcefromtheserver.Theremainderof

therequestprovidesthepathnameoftheresource(e.g.,an

XHTMLdocument)andtheprotocol'snameandversionnumber

(HTTP/1.1).Theclient'srequestalsocontainssomerequired

andoptionalheaders.

AnyserverthatunderstandsHTTP(version1.1)cantranslate

thisrequestandrespondappropriately.Figure17.2depictsthe

serverrespondingtoarequest.Theserverfirstrespondsby

sendingalineoftextthatindicatestheHTTPversion,followed

byanumericcodeandaphrasedescribingthestatusofthe

transaction.Forexample,

HTTP/1.1200OK



indicatessuccess,whereas

HTTP/1.1404Notfound



informstheclientthatthewebservercouldnotlocatethe

requestedresource.Acompletelistofnumericcodesindicating

thestatusofanHTTPtransactioncanbefoundat

www.w3.org/Protocols/rfc2616/rfc2616-sec10.html.

Figure17.2.Clientinteractingwithwebserver.Step2:

TheHTTPresponse.

[Viewfullsizeimage]



HTTPHeaders

TheserverthensendsoneormoreHTTPheaders,which

provideadditionalinformationaboutthedatathatwillbesent.

Inthiscase,theserverissendinganXHTMLtextdocument,so

oneHTTPheaderforthisexamplewouldread:

Content-type:text/html



Theinformationprovidedinthisheaderspecifiesthe

MultipurposeInternetMailExtensions(MIME)typeofthe

contentthattheserveristransmittingtothebrowser.MIMEis

anInternetstandardthatspecifiesdataformatssothat

programscaninterpretdatacorrectly.Forexample,theMIME

typetext/plainindicatesthatthesentinformationistextthat

canbedisplayeddirectly,withoutanyinterpretationofthe

contentasXHTMLmarkup.Similarly,theMIMEtype



image/jpegindicatesthatthecontentisaJPEGimage.When

thebrowserreceivesthisMIMEtype,itattemptstodisplaythe

image.

Theheaderorsetofheadersisfollowedbyablankline,which

indicatestotheclientbrowserthattheserverisfinished

sendingHTTPheaders.Theserverthensendsthecontentsof

therequestedXHTMLdocument(downloads.html).TheclientsidebrowserparsestheXHTMLmarkupitreceivesandrenders

(ordisplays)theresults.Theservernormallykeepsthe

connectionopentoprocessotherrequestsfromtheclient.



HTTPgetandpostRequests

ThetwomostcommonHTTPrequesttypes(alsoknownas

requestmethods)aregetandpost.Agetrequesttypically

gets(orretrieves)informationfromaserver.Commonusesof

getrequestsaretoretrieveanXHTMLdocumentoranimage,

ortofetchsearchresultsbasedonauser-submittedsearch

term.Apostrequesttypicallyposts(orsends)datatoaserver.

Commonusesofpostrequestsaretosendformdataor

documentstoaserver.

AnHTTPrequestoftenpostsdatatoaserver-sideform

handlerthatprocessesthedata.Forexample,whenauser

performsasearchorparticipatesinaweb-basedsurvey,the

webserverreceivestheinformationspecifiedintheXHTML

formaspartoftherequest.Getrequestsandpostrequests

canbothbeusedtosendformdatatoawebserver,yeteach

requesttypesendstheinformationdifferently.

Agetrequestsendsinformationtotheserveraspartofthe

URL,e.g.,www.google.com/search?q=deitel.Inthiscase

searchisthenameofGoogle'sserver-sideformhandler,qis

thenameofavariableinGoogle'ssearchformanddeitelisthe

searchterm.Noticethe?intheprecedingURL.A?separates

thequerystringfromtherestoftheURLinarequest.A



name/valuepairispassedtotheserverwiththenameandthe

valueseparatedbyanequalssign(=).Ifmorethanone

name/valuepairissubmitted,eachpairisseparatedbyan

ampersand(&).Theserverusesdatapassedinaquerystring

toretrieveanappropriateresourcefromtheserver.Theserver

thensendsaresponsetotheclient.Agetrequestmaybe

initiatedbysubmittinganXHTMLformwhosemethodattribute

issetto"get",orbytypingtheURL(possiblycontaininga

querystring)directlyintothebrowser'saddressbar.

ApostrequestisspecifiedinanXHTMLformbythemethod

"post".ThepostmethodsendsformdataaspartoftheHTTP

message,notaspartoftheURL.Agetrequesttypicallylimits

thequerystring(i.e.,everythingtotherightofthe?)toa

specificnumberofcharacters(2083inIE;moreinother

browsers),soitisoftennecessarytosendlargepiecesof

informationusingthepostmethod.Thepostmethodisalso

sometimespreferredbecauseithidesthesubmitteddatafrom

theuserbyembeddingitinanHTTPmessage.Ifaform

submitsseveralhiddeninputvaluesalongwithuser-submitted

data,thepostmethodmightgenerateaURLlike

www.searchengine.com/search.Theformdatastillreachesthe

serverandisprocessedinasimilarfashiontoagetrequest,

buttheuserdoesnotseetheexactinformationsent.

SoftwareEngineeringObservation17.1

Thedatasentinapostrequestisnotpart

oftheURLandtheusercan'tseethedata

bydefault.Howevertherearetools

availablethatexposethisdata,soyou

shouldnotassumethatthedataissecure

justbecauseapostrequestisused.



Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Chapter 17. Web Servers (IIS and Apache)

Tải bản đầy đủ ngay(0 tr)

×