Download presentation
Presentation is loading. Please wait.
1
CSE 190: Internet Commerce Lecture 4: Web Servers
2
Web Servers What do they do? How do they work? Apache: Installation, Configuration Apache: Administration Special Topics
3
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
4
Commercial Implementations Apache IIS Netscape Commerce Server Netcraft data for active servers (http://www.netcraft.com/survey/)
5
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 –200s (Success) –300s (Redirect) –400s (Bad request) –500s (Server Failure)
6
HTTP Illustrated GET / HTTP/1.0 –Standard HTTP/1.0 request for main site page GET /ex1.html HTTP/1.0 –Standard request for the ex1.html page GET /ex1.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 /ex1.html HTTP/1.1 Hostname: gremlin.ucsd.edu –A pipelined request
7
HTTP Illustrated (POST, HEAD) HEAD / HTTP/1.0 –Just view what headers are returned by GET POST /cgi-bin/ex2.pl HTTP/1.0 Content-Length: 25 user=guest&pass=secret –Posts two parameters to a script
8
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=
9
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
10
How does a web server work? Multiple clients (Apache model) Parent: Listen on Port (server default: 80) Fork StartServers number of child processes Wait forever and periodically, If #children < MinSpareServers, fork a new child If #children < MaxSpareServers, kill any child not handling request Child: while (true) Accept client connection Parse request, send response Increment request_count If request_count > MaxRequestPerChild then exit
11
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
12
Apache: Installation Download from apache.org –http://www.apache.org/dist/httpd/binaries/solaris/http://www.apache.org/dist/httpd/binaries/solaris/ gunzip –c apache-…tar.gz | tar xvf -./configure --prefix =$HOME/apache make make install ~/apache/bin/apachectl start Test by telnet localhost 8080
13
Apache: Configuration (Starting) Port (Usually 80 when deployed; must be unique for the machine) DocumentRoot (Directory for files) ServerName (Domain name for server) User (for root only: specify Unix user id) To validate: apachectl configtest
14
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
15
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
16
Special Topics Virtual Domain Hosting –Serve multiple web sites from the same machine –Name based or IP based Syntax: NameVirtualHost * ServerAdmin sinala@gremlin.ucsd.edu DocumentRoot "/home/sinala/apache/htdocs" ServerName gremlin.ucsd.edu ErrorLog logs/error_log CustomLog logs/access_log common ServerAdmin webmaster@mysite.com DocumentRoot "/home/sinala/apache/htdocs/mysite" Port 8080 ServerName mysite.com ErrorLog logs/mysite-error_log CustomLog logs/mysite-access_log common
17
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
19
HTTP authentication MIME types Proxies Expected performance Multilanguage
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.