Web Server Admin Don Porter CSE/ISE 311: Systems - - PowerPoint PPT Presentation

web server admin
SMART_READER_LITE
LIVE PREVIEW

Web Server Admin Don Porter CSE/ISE 311: Systems - - PowerPoint PPT Presentation

CSE/ISE 311: Systems Administra5on Web Server Admin Don Porter CSE/ISE 311: Systems Administra5on Web Serving Sta0c Content Dynamic Content and


slide-1
SLIDE 1

CSE/ISE ¡311: ¡Systems ¡Administra5on ¡

Web ¡Server ¡Admin ¡

Don ¡Porter ¡

slide-2
SLIDE 2

CSE/ISE ¡311: ¡Systems ¡Administra5on ¡

Web ¡Serving ¡

  • Sta0c ¡Content ¡
  • Dynamic ¡Content ¡and ¡Security ¡
  • Distribu0on ¡and ¡Scaling ¡
slide-3
SLIDE 3

CSE/ISE ¡311: ¡Systems ¡Administra5on ¡

HTTP ¡

  • HyperText ¡Transport ¡Protocol ¡

– Usually ¡implemented ¡on ¡TCP ¡port ¡80 ¡

  • Simple, ¡stateless ¡

– Most ¡conversa0ons ¡are: ¡connect, ¡get ¡something, ¡close ¡ connec0on ¡

  • You ¡can ¡actually ¡telnet ¡to ¡a ¡web ¡server ¡and ¡type ¡

HTTP ¡commands! ¡ $ ¡telnet ¡www.oscar.cs.stonybrook.edu ¡80 ¡ GET ¡/ ¡

slide-4
SLIDE 4

CSE/ISE ¡311: ¡Systems ¡Administra5on ¡

Apache ¡Web ¡Server ¡

  • Lots ¡of ¡good ¡web ¡servers ¡out ¡there: ¡IIS, ¡lighQpd, ¡etc. ¡

– Apache ¡is ¡a ¡very ¡popular ¡one, ¡though. ¡ – Most ¡people ¡use ¡version ¡2 ¡

  • Fairly ¡simple ¡to ¡install ¡
  • Can ¡be ¡configured ¡to ¡run ¡mul0ple ¡sites ¡on ¡the ¡same ¡

server ¡

slide-5
SLIDE 5

CSE/ISE ¡311: ¡Systems ¡Administra5on ¡

Simple ¡Example ¡Apache ¡hQp.conf ¡

# ¡Ensure ¡that ¡Apache ¡listens ¡on ¡port ¡80 ¡ Listen ¡80 ¡ ¡ # ¡Listen ¡for ¡virtual ¡host ¡requests ¡on ¡all ¡IP ¡addresses ¡ NameVirtualHost ¡*:80 ¡ ¡ <VirtualHost ¡*:80> ¡ DocumentRoot ¡/www/example1 ¡ ServerName ¡www.example.com ¡ ¡ # ¡Other ¡direc0ves ¡here ¡ ¡ </VirtualHost> ¡ ¡ <VirtualHost ¡*:80> ¡ DocumentRoot ¡/www/example2 ¡ ServerName ¡www.example.org ¡ ¡ # ¡Other ¡direc0ves ¡here ¡ ¡ </VirtualHost> ¡

From: ¡hQp://hQpd.apache.org/docs/2.2/vhosts/examples.html ¡

slide-6
SLIDE 6

CSE/ISE ¡311: ¡Systems ¡Administra5on ¡

Key ¡Points ¡

  • Easy ¡to ¡host ¡mul0ple ¡sites: ¡

– Just ¡define ¡a ¡new ¡virtual ¡hosts ¡

  • DocumentRoot: ¡ ¡

– Just ¡a ¡directory ¡full ¡of ¡html, ¡javascript, ¡css, ¡etc. ¡ – index.html ¡is ¡the ¡default ¡page ¡if ¡none ¡specified ¡

slide-7
SLIDE 7

CSE/ISE ¡311: ¡Systems ¡Administra5on ¡

Other ¡useful ¡direc0ves ¡

  • ErrorLog: ¡specify ¡the ¡file ¡for ¡error ¡messages ¡

– Useful ¡for ¡debugging, ¡can ¡be ¡different ¡per ¡VirtualHost ¡

  • ServerAdmin: ¡specify ¡the ¡email ¡address ¡of ¡the ¡site ¡

admin ¡(you) ¡

slide-8
SLIDE 8

CSE/ISE ¡311: ¡Systems ¡Administra5on ¡

.htaccess ¡

  • Site ¡owners ¡can ¡specify ¡access ¡control ¡on ¡files ¡using ¡a ¡file ¡

called ¡.htaccess ¡(in ¡the ¡same ¡dir ¡with ¡content) ¡

  • Example ¡(only ¡allow ¡access ¡from ¡SBU): ¡

<Limit GET>

  • rder deny, allow

deny from all allow from .sunysb.edu allow from .stonybrook.edu allow from 129.49. allow from 130.245. </Limit>

slide-9
SLIDE 9

CSE/ISE ¡311: ¡Systems ¡Administra5on ¡

Dynamic ¡Content ¡

  • Most ¡of ¡the ¡web ¡isn’t ¡just ¡simple ¡web ¡pages ¡

anymore ¡

  • You ¡can ¡think ¡of ¡most ¡pages ¡as ¡interac0ve ¡

applica0ons ¡

– E.g., ¡Facebook ¡shows ¡different ¡pages ¡to ¡different ¡users ¡

slide-10
SLIDE 10

CSE/ISE ¡311: ¡Systems ¡Administra5on ¡

Idea: ¡Server-­‑side ¡Apps ¡

  • Rather ¡than ¡just ¡return ¡the ¡contents ¡of ¡an ¡html ¡file ¡
  • Run ¡a ¡program ¡that ¡outputs ¡html, ¡return ¡that ¡
  • Similar ¡to ¡a ¡Unix ¡pipe ¡
slide-11
SLIDE 11

CSE/ISE ¡311: ¡Systems ¡Administra5on ¡

Common ¡Gateway ¡Interface ¡(CGI) ¡

  • Basically, ¡just ¡a ¡standard ¡for ¡how ¡to ¡pass ¡input/
  • utput ¡between ¡a ¡web ¡server ¡and ¡an ¡applica0on ¡
  • CGI ¡applica0ons ¡can ¡be ¡implemented ¡in ¡any ¡

language ¡

– Perl, ¡PHP, ¡Python, ¡Ruby ¡are ¡popular ¡

slide-12
SLIDE 12

CSE/ISE ¡311: ¡Systems ¡Administra5on ¡

Storing ¡Data ¡

  • Suppose ¡I ¡want ¡to ¡store ¡data ¡input ¡by ¡the ¡user ¡

– E.g., ¡a ¡Facebook-­‑style ¡wall ¡of ¡status ¡posts ¡

  • I ¡could ¡put ¡these ¡in ¡a ¡file ¡on ¡the ¡server ¡
  • But ¡ohen ¡easier ¡to ¡use ¡a ¡database ¡

– Decouples ¡data ¡management ¡from ¡deploying ¡scripts ¡

slide-13
SLIDE 13

CSE/ISE ¡311: ¡Systems ¡Administra5on ¡

LAMP ¡Stack ¡

  • Linux ¡Apache ¡MySQL ¡Perl/PHP/Python ¡
  • MySQL ¡is ¡a ¡popular, ¡open-­‑source ¡database ¡
  • Many ¡Linux ¡server ¡installa0on ¡discs ¡make ¡it ¡easy ¡to ¡

bring ¡up ¡a ¡LAMP ¡stack ¡quickly ¡

slide-14
SLIDE 14

CSE/ISE ¡311: ¡Systems ¡Administra5on ¡

Script ¡Security ¡

  • When ¡you ¡run ¡a ¡script ¡on ¡your ¡server, ¡that ¡script ¡is ¡

(generally) ¡just ¡like ¡any ¡other ¡program ¡on ¡your ¡ server ¡

  • A ¡compromised ¡script ¡can ¡compromise ¡your ¡server ¡
  • Proceed ¡with ¡cau0on ¡
  • A ¡lot ¡of ¡script ¡security ¡amounts ¡to ¡being ¡resilient ¡to ¡

carefully ¡crahed, ¡malicious ¡inputs ¡

  • And ¡limi0ng ¡the ¡damage ¡a ¡bad ¡script ¡can ¡do ¡
slide-15
SLIDE 15

CSE/ISE ¡311: ¡Systems ¡Administra5on ¡

Input ¡Example ¡

  • Suppose ¡I ¡am ¡a ¡script ¡that ¡stores ¡user ¡profiles ¡as ¡

<name>.txt ¡

  • I ¡have ¡a ¡form ¡on ¡my ¡webpage ¡that ¡asks ¡for ¡a ¡name: ¡

name ¡= ¡form_input(“name”); ¡ profile ¡= ¡execute(“cat ¡“ ¡+ ¡name ¡+ ¡“.txt”); ¡ print ¡profile; ¡ ¡

  • Any ¡issues? ¡
slide-16
SLIDE 16

CSE/ISE ¡311: ¡Systems ¡Administra5on ¡

Code ¡injec0on ¡

  • What ¡if ¡I ¡type ¡in ¡as ¡my ¡name: ¡ ¡

¡Insecure.txt; ¡rm ¡*; ¡echo ¡Hahahaha> ¡pwned ¡ ¡ profile ¡= ¡execute(“cat ¡“ ¡+ ¡name); ¡ = ¡execute( ¡“cat ¡Insecure.txt; ¡rm ¡*; ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡echo ¡Hahaha ¡> ¡pwned.txt”) ¡ ¡

slide-17
SLIDE 17

CSE/ISE ¡311: ¡Systems ¡Administra5on ¡

How ¡to ¡deal ¡with ¡inputs? ¡

  • In ¡general, ¡you ¡have ¡to ¡carefully ¡check ¡that ¡they ¡are ¡

what ¡you ¡expect ¡

– No ¡escape ¡characters ¡or ¡other ¡unusual ¡strings ¡

  • Perl ¡has ¡something ¡called ¡“Taint ¡mode” ¡
  • Basically, ¡scripts ¡that ¡use ¡unchecked ¡input ¡as ¡output ¡

to ¡a ¡command ¡will ¡be ¡killed ¡

– Developer ¡s0ll ¡has ¡to ¡write ¡good ¡checks ¡

slide-18
SLIDE 18

CSE/ISE ¡311: ¡Systems ¡Administra5on ¡

Sandboxing ¡

  • In ¡order ¡to ¡limit ¡the ¡damage ¡of ¡a ¡bad ¡script, ¡you ¡may ¡

also ¡want ¡to ¡run ¡it ¡in ¡a ¡sandbox ¡

  • BSD ¡has ¡something ¡called ¡a ¡jail: ¡limited ¡view ¡of ¡the ¡

file ¡system, ¡limited ¡access ¡to ¡system ¡resources ¡

  • Other ¡sandboxing ¡tools ¡exist ¡for ¡this ¡purpos ¡
slide-19
SLIDE 19

CSE/ISE ¡311: ¡Systems ¡Administra5on ¡

JavaScript ¡

  • In ¡addi0on ¡to ¡running ¡code ¡on ¡a ¡web ¡server ¡to ¡

generate ¡content, ¡you ¡can ¡also ¡load ¡code ¡into ¡a ¡ user’s ¡browser ¡

– Service ¡some ¡clicks ¡locally ¡

  • JavaScript ¡is ¡the ¡main ¡language ¡for ¡client-­‑side ¡coding ¡
slide-20
SLIDE 20

CSE/ISE ¡311: ¡Systems ¡Administra5on ¡

AJAX ¡and ¡Web ¡2.0 ¡

  • Most ¡recent ¡web ¡apps ¡use ¡a ¡combina0on ¡of ¡

Javascript ¡on ¡the ¡client ¡and ¡a ¡server-­‑side ¡applica0on ¡

  • Server-­‑Side ¡app ¡may ¡not ¡generate ¡whole ¡pages, ¡but ¡

may ¡handle ¡smaller ¡requests ¡

– XML ¡is ¡ohen ¡used ¡to ¡exchange ¡data ¡between ¡Javascript ¡ and ¡the ¡server ¡ – Hence ¡the ¡name: ¡Asynchronous ¡Javascript ¡And ¡XML ¡

slide-21
SLIDE 21

CSE/ISE ¡311: ¡Systems ¡Administra5on ¡

Scaling ¡Up ¡

  • As ¡we’ve ¡discussed ¡before, ¡round-­‑robin ¡DNS ¡lets ¡you ¡

have ¡mul0ple ¡web ¡servers ¡

  • And ¡running ¡a ¡database ¡on ¡the ¡back-­‑end ¡lets ¡you ¡

have ¡mul0ple ¡front-­‑end ¡CGI ¡scripts ¡

  • You ¡can ¡also ¡run ¡more ¡web ¡servers ¡in ¡the ¡cloud ¡
slide-22
SLIDE 22

CSE/ISE ¡311: ¡Systems ¡Administra5on ¡

Content ¡Distribu0on ¡Networks ¡(CDN) ¡

  • Big ¡content ¡providers ¡can ¡improve ¡latency ¡and ¡

reduce ¡their ¡own ¡bandwidth ¡by ¡placing ¡data ¡close ¡to ¡ users ¡

– E.g., ¡nerlix, ¡facebook, ¡etc. ¡ – Read-­‑only ¡data ¡ – Why ¡should ¡NY ¡users ¡have ¡to ¡pull ¡all ¡of ¡their ¡data ¡from ¡ CA? ¡

  • Companies ¡like ¡Akamai ¡transparently ¡redirect ¡you ¡to ¡

the ¡geographically ¡closest ¡server ¡for ¡your ¡content ¡

  • PreQy ¡expensive ¡op0on, ¡mostly ¡for ¡bigger ¡ventures ¡
slide-23
SLIDE 23

CSE/ISE ¡311: ¡Systems ¡Administra5on ¡

Proxying, ¡Caching, ¡and ¡Filtering ¡

  • Many ¡organiza0ons ¡only ¡allow ¡outgoing ¡web ¡traffic ¡

through ¡a ¡proxy ¡server ¡

  • 2 ¡main ¡reasons: ¡

– Caching: ¡Can ¡store ¡(sta0c, ¡public) ¡pages ¡and ¡serve ¡locally, ¡ saving ¡bandwidth ¡ – Filtering: ¡Can ¡refuse ¡to ¡let ¡you ¡see ¡facebook, ¡or ¡illicit ¡pages ¡