tutorial shengdong zhao sszhao (some slides are reused/modified from neil ernst’s apache tutorial)

21
Tutorial Shengdong Zhao http://www.dgp.toronto.edu/~sszhao (some slides are reused/modified from Neil Ernst’s apache tutoria

Upload: myra-pierce

Post on 05-Jan-2016

220 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Tutorial Shengdong Zhao sszhao (some slides are reused/modified from Neil Ernst’s apache tutorial)

Tutorial

Shengdong Zhaohttp://www.dgp.toronto.edu/~sszhao

(some slides are reused/modified from Neil Ernst’s apache tutorial)

Page 2: Tutorial Shengdong Zhao sszhao (some slides are reused/modified from Neil Ernst’s apache tutorial)

History

• Based on Rob McCool’s NCSA web server (left to start Netscape 1994)

• 1st release (Apache 0.7.x) on April 1995 based on NSCA 1.3 server

• Patches created for extensions and bug-fixes (Apache = A-patchy Server)

• Today – 52.65% of all web server (July 07, www.netcraft.com)

• 2 streams: 1.3.x (very popular) & 2.x (current)

Page 3: Tutorial Shengdong Zhao sszhao (some slides are reused/modified from Neil Ernst’s apache tutorial)
Page 4: Tutorial Shengdong Zhao sszhao (some slides are reused/modified from Neil Ernst’s apache tutorial)

Apache Architecture

http://plg.uwaterloo.ca/~aeehassa/cs746/as1/apache1.htm

Page 5: Tutorial Shengdong Zhao sszhao (some slides are reused/modified from Neil Ernst’s apache tutorial)

Apache Architecture

• Select module handler at install • Modules hook into phases in the Core processi

ng cycle via API• Apache talks to clients use HTTP protocol

– Client request: GET /index.html– Apache maps request to a handler or file– Authenticate– Return content with headers– Modules can hook in at any point during the protocol

Page 6: Tutorial Shengdong Zhao sszhao (some slides are reused/modified from Neil Ernst’s apache tutorial)

Headers

• Check out the LiveHTTPHeaders extension for Firefox: view the entire transaction.

• Headers usually tell the client the status of the request, the mime-type of the content returned, the length, etc.– Allows the client to decide what to do.

Page 7: Tutorial Shengdong Zhao sszhao (some slides are reused/modified from Neil Ernst’s apache tutorial)
Page 8: Tutorial Shengdong Zhao sszhao (some slides are reused/modified from Neil Ernst’s apache tutorial)

• GET / HTTP/1.1• Host: www.yahoo.com• User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.4) Gecko/200

70515 Firefox/2.0.0.4• Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,

image/png,*/*;q=0.5• Accept-Language: en-us,en;q=0.5• Accept-Encoding: gzip,deflate• Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7• Keep-Alive: 300• Connection: keep-alive• Cookie: …

• HTTP/1.x 200 OK• Date: Tue, 10 Jul 2007 20:47:16 GMT• P3P: policyref="http://p3p.yahoo.com/w3c/p3p.xml", CP="CAO DSP COR CUR ADM

DEV TAI PSA PSD IVAi IVDi CONi TELo OTPi OUR DELi SAMi OTRi UNRi PUBi IND PHY ONL UNI PUR FIN COM NAV INT DEM CNT STA POL HEA PRE GOV"

• Cache-Control: private• Vary: User-Agent• Set-Cookie: FPCM=deleted; expires=Mon, 10 Jul 2006 20:47:15 GMT; path=/• Set-Cookie: …• Connection: close• Transfer-Encoding: chunked• Content-Type: text/html; charset=utf-8• Content-Encoding: gzip

Page 9: Tutorial Shengdong Zhao sszhao (some slides are reused/modified from Neil Ernst’s apache tutorial)

Modules

• The power of Apache is its modules– mod_ssl: Secure internet transactions– mod_rewrite: redirect agents elsewhere– mod_perl: PERL language interface– mod_log_config: logging– mod_include: filter other modules

Page 10: Tutorial Shengdong Zhao sszhao (some slides are reused/modified from Neil Ernst’s apache tutorial)

Apache on CDFWe run instances of the Apache server daemon (ht

tpd) using our own config files (no install!) – version 2.0.52

1 – course web page student guide Apache and follow the instructions

2 – download the tar file apache.tar.gz3 – save it and untar it to a suitable folder, e.g. ~/3

09/ (tar –xvzf apache.tar.gz)4 – cd ~/309/apache/bin; ./start.sh <portnum> This

starts the server; stop it using ./stop.sh5 – verify: ps –u <user> | grep httpd6 – view: lynx http://localhost:<portnum>/

Page 11: Tutorial Shengdong Zhao sszhao (some slides are reused/modified from Neil Ernst’s apache tutorial)
Page 12: Tutorial Shengdong Zhao sszhao (some slides are reused/modified from Neil Ernst’s apache tutorial)
Page 13: Tutorial Shengdong Zhao sszhao (some slides are reused/modified from Neil Ernst’s apache tutorial)
Page 14: Tutorial Shengdong Zhao sszhao (some slides are reused/modified from Neil Ernst’s apache tutorial)

Directory Structure

• Bin: the start and stop programs• Conf: the config file for your server instances• Cgi-bin: put executable scripts here• Logs: error_log is any errors the server gets (40

4, 403), and access_log all accesses the server deals with

• htdocs: html files• E.g. – see examples in each directory and play a

round

Page 15: Tutorial Shengdong Zhao sszhao (some slides are reused/modified from Neil Ernst’s apache tutorial)

Configure Apache

• Shouldn’t need to change much in the /conf directory (mainly httpd.309.conf)

• Can set your DocumentRoot in httpd.conf:– DocumentRoot /where/you/want/to/put/you

r/docs

• Can set your web admin e-mails – ServerAdmin [email protected]

Page 16: Tutorial Shengdong Zhao sszhao (some slides are reused/modified from Neil Ernst’s apache tutorial)

Demo

Page 17: Tutorial Shengdong Zhao sszhao (some slides are reused/modified from Neil Ernst’s apache tutorial)

Work at home

1. Install and config Cygwin

http://www.cdf.toronto.edu/workathome/print.php3?id=76

2. Double click Cygwin icon to start

3. Type “startx” to start x window

4. At the popup xterm, type “ssh -X [email protected]” to login to your account

Page 18: Tutorial Shengdong Zhao sszhao (some slides are reused/modified from Neil Ernst’s apache tutorial)

FAQs

• Can I run this all at home, on Windows/Mac?– Sure. Apache even runs on Xbox. However, we mark

assignments on CDF

• How do I view my server on the internet?– http://<XXXwolf>.cdf.toronto.edu:<portnum>– http://<localmachine>.cdf.toronto.edu:<portnum> in th

e labs

• My start/stop aren’t working?– Always start/stop directly in apache/bin to make sure

paths work properly

Page 19: Tutorial Shengdong Zhao sszhao (some slides are reused/modified from Neil Ernst’s apache tutorial)

Other references

• The student guide on the course site• httpd.apache.org (e.g.)

– http://httpd.apache.org/docs/1.3/howto/htaccess.html– http://httpd.apache.org/docs/1.3/howto/auth.html#basi

c

• Refcards.com – Apache 1.3 reference card for printing (also other useful cards) http://refcards.com/docs/forda/apache/apache-refcard-a4.pdf

Page 20: Tutorial Shengdong Zhao sszhao (some slides are reused/modified from Neil Ernst’s apache tutorial)

.htaccess files

• Use .htaccess files– These are read per-directory (affect subs) by t

he server and can contain many things• Security restrictions• Redirects• URL rewrites

Page 21: Tutorial Shengdong Zhao sszhao (some slides are reused/modified from Neil Ernst’s apache tutorial)

.htaccess files: sample format

order allow, denydeny from 123.45.6.7deny from 012.34.5Allow from allAuthUserFile /

user/local/you/safedir/.htpasswdAuthGroupFile /dev/nullAuthName EnterPasswordAuthType BasicRequire user wsabstract