Скачать презентацию CSE 190 Internet Commerce Lecture 4 Web Servers Скачать презентацию CSE 190 Internet Commerce Lecture 4 Web Servers

9411fefa863e55e81d63aebeb2bca243.ppt

  • Количество слайдов: 19

CSE 190: Internet Commerce Lecture 4: Web Servers CSE 190: Internet Commerce Lecture 4: Web Servers

Web Servers • • • What do they do? How do they work? Apache: Web Servers • • • What do they do? How do they work? Apache: Installation, Configuration Apache: Administration Special Topics

What does a web server do? • A web server serves files to clients What does a web server do? • A web server serves files to clients (such as the browser) • Files may be HTML, GIFs, video, PDF • Serves multiple clients at the same time • Transfer protocol: HTTP

Commercial Implementations • Apache • IIS • Netscape Commerce Server Netcraft data for active Commercial Implementations • Apache • IIS • Netscape Commerce Server Netcraft data for active servers (http: //www. netcraft. com/survey/)

HTTP • • • Simple text command-response protocol Always uses TCP/IP (connection oriented) Methods: HTTP • • • Simple text command-response protocol Always uses TCP/IP (connection oriented) Methods: GET, POST, HEAD Stateless protocol: no client identifier Uses 8 bit bytes (octets) HTTP Versions: 0. 9 (assumes HTML), 1. 0 (client/server headers), 1. 1 (persistent connections) • HTTP status codes – – 200 s (Success) 300 s (Redirect) 400 s (Bad request) 500 s (Server Failure)

HTTP Illustrated • GET / HTTP/1. 0 – Standard HTTP/1. 0 request for main HTTP Illustrated • GET / HTTP/1. 0 – Standard HTTP/1. 0 request for main site page • GET /ex 1. html HTTP/1. 0 – Standard request for the ex 1. html page • GET /ex 1. gif HTTP/1. 0 – Request an image file (image/gif) • GET /notthere. html HTTP/1. 0 – Returns 404 (Not found) response • GET / – An HTTP/0. 9 request • GET / HTTP/1. 1 Hostname: gremlin. ucsd. edu GET /ex 1. html HTTP/1. 1 Hostname: gremlin. ucsd. edu – A pipelined request

HTTP Illustrated (POST, HEAD) • HEAD / HTTP/1. 0 – Just view what headers HTTP Illustrated (POST, HEAD) • HEAD / HTTP/1. 0 – Just view what headers are returned by GET • POST /cgi-bin/ex 2. pl HTTP/1. 0 Content-Length: 25 user=guest&pass=secret – Posts two parameters to a script

HTTP Illustrated (Realistic request) GET /x. html HTTP/1. 1 Connection: Keep-Alive Accept: image/gif, image/x-xbitmap, HTTP Illustrated (Realistic request) GET /x. html HTTP/1. 1 Connection: Keep-Alive Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd. ms-excel, application/vnd. ms-powerpoint, application/msword, */* Accept-Encoding: gzip, deflate Accept-Language: en-us Host: gremlin. ucsd. edu: 60846 User-Agent: Mozilla/4. 0 (compatible; MSIE 6. 0; Windows NT 5. 0) Cookie: bookcookie=

How does a web server work? • Serial request model (Example: printhttp. pl) while How does a web server work? • Serial request model (Example: printhttp. pl) while (true) accept client connection read HTTP request parse request pathname = req. uri_details send HTTP response header foreach byte in file pathname send byte to client close client connection • Pitfall: Requests from other clients have to wait

How does a web server work? • Multiple clients (Apache model) Parent: Listen on How does a web server work? • Multiple clients (Apache model) Parent: Listen on Port (server default: 80) Fork Start. Servers number of child processes Wait forever and periodically, If #children < Min. Spare. Servers, fork a new child If #children < Max. Spare. Servers, kill any child not handling request Child: while (true) Accept client connection Parse request, send response Increment request_count If request_count > Max. Request. Per. Child then exit

Apache model • Provides multiple processes to handle simultaneous requests • Throttles the number Apache model • Provides multiple processes to handle simultaneous requests • Throttles the number of child processes • Crashing a child process doesn’t crash the server; the parent is very stable • Memory leaks don’t take down the machine; memory freed when child exits • Note: IIS uses similar model, but with threads instead of processes • Extending Apache through modules – Core, mime, auth, cookies, redirect

Apache: Installation • Download from apache. org – http: //www. apache. org/dist/httpd/binaries/solaris/ • • Apache: Installation • Download from apache. org – http: //www. apache. org/dist/httpd/binaries/solaris/ • • • gunzip –c apache-…tar. gz | tar xvf. /configure --prefix =$HOME/apache make install ~/apache/bin/apachectl start Test by telnet localhost 8080

Apache: Configuration (Starting) • Port (Usually 80 when deployed; must be unique for the Apache: Configuration (Starting) • Port (Usually 80 when deployed; must be unique for the machine) • Document. Root (Directory for files) • Server. Name (Domain name for server) • User (for root only: specify Unix user id) • To validate: apachectl configtest

Apache: Administration • Starting – apachectl start; verify with ps -ef • Stopping – Apache: Administration • Starting – apachectl start; verify with ps -ef • Stopping – apachectl stop: kills `cat logs/httpd. pid` • Viewing logs – access_log: host ident authuser date request status bytes – error_log: date priority host error • Log rotation (rotatelogs); excessive logging

Special Topics • SSL – – – What it is, how it works (handshake, Special Topics • SSL – – – What it is, how it works (handshake, key gen, authen, client auth) Traffic flows over the https port 443 Added with mod_ssl Getting a server certificate (Verisign: $350 -$1000) Overhead to SSL requests

Special Topics • • Virtual Domain Hosting – Serve multiple web sites from the Special Topics • • Virtual Domain Hosting – Serve multiple web sites from the same machine – Name based or IP based Syntax: Name. Virtual. Host * Server. Admin [email protected] ucsd. edu Document. Root "/home/ sinala/apache/htdocs" Server. Name gremlin. ucsd. edu Error. Log logs/error_log Custom. Log logs/access_log common Server. Admin [email protected] com Document. Root "/home/ sinala/apache/htdocs/mysite " Port 8080 Server. Name mysite. com Error. Log logs/mysite-error_log Custom. Log logs/mysite-access_log common

Special Topics • CGI (Common Gateway Interface) – Initial way to add interactivity – Special Topics • CGI (Common Gateway Interface) – Initial way to add interactivity – Uses mod_cgi – Slow: new process created per request – Perl Example: /cgi-bin/rumple

 • • • HTTP authentication MIME types Proxies Expected performance Multilanguage • • • HTTP authentication MIME types Proxies Expected performance Multilanguage