Architecture, CDF, CGIsNeil ErnstTutorial Overview●Background on Apache●Apache architecture–Modules and what they can do●Running Apache on CDF machines●What is Apache good for?●FAQsBackground●So there's this thing called the 'interweb'–And a lot of it runs on Apache●Apache – First Peoples from SouthWest U.S.–(A patchy?)●Apache – most successful OSS project(?)●Apache – a project (Jakarta, Ant), and a server●Apache – webserver in use in 64% of sites●2 streams: 1.3.x (very popular) & 2.x (current)Apache architecture●Modular: select module handler at install (MPM)–e.g. What type of threading model–A core of basic functions, and modules for rest●Modules hook into phases in the processing cycle via API●Apache works off the HTTP (request/response) 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 (e.g., mod_ssl)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.Host: en.wikipedia.orgUser-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.7.8) Gecko/20050511 Firefox/1.0.4Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5Accept-Language: en-gb,en;q=0.5Accept-Encoding: gzip,deflateAccept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7Keep-Alive: 300Connection: keep-aliveIf-Modified-Since: Wed, 25 May 2005 16:27:46 GMTCache-Control: max-age=0HTTP/1.x 304 Not ModifiedDate: Mon, 06 Jun 2005 20:35:20 GMTServer: ApacheX-Powered-By: PHP/4.3.11Vary: Accept-Encoding,CookieCache-Control: private, s-maxage=0, max-age=0, must-revalidateLast-Modified: Wed, 25 May 2005 16:27:46 GMTContent-Encoding: gzipContent-Type: text/htmlX-Cache: MISS from srv10.wikimedia.orgConnection: keep-aliveConfiguring Apache●Shouldn't need to change much in the /conf directory–But feel free●Best strategy is to use .htaccess files–These are read per-directory (affect subs) by the server and can contain many things●Security restrictions●Redirects●URL rewrites.htaccess files: sample formatorder allow,denydeny from 123.45.6.7deny from 012.34.5.allow from allAuthUserFile /usr/local/you/safedir/.htpasswdAuthGroupFile /dev/nullAuthName EnterPasswordAuthType Basicrequire user wsabstractModules●Virtuous cycle: Free Software, module architectures, demand●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 modulesApache on CDF●We run instances of the Apache server daemon (httpd) using our own config files (no install!) - version 2.0.52●1 – go to course web page, then the guide, and follow the instructions●2 – download the tar file apache.tar.gz●3 – save it and untar it to a suitable folder, e.g. ~/309/ (tar -xvfz apache.tar.gz)●4 - cd ~/309/apache/bin; ./start.sh <portnum>●This starts the server; please stop it in the same fashion●5 – Verify: ps -u <user> | grep httpd●6 – View: lynx http://localhost:<port num>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 (404, 403), and access_log all accesses the server deals with●Htdocs: serves up html files per usual●E.g. - see examples in each directory and play around.CGI files●CGI is a spec for using a 'gateway' to redirect requests to executable files on the server●A CGI is just a program on the server in a special location (to minimize damage) that runs as user who starts server (you!)●Perl, python, C++, FORTRAN can all be CGIs●For our purposes, we stick our executable (+x) files in /apache/cgi-bin●Certain special variables are available courtesy the CGI interface●Also pass variables in via query string●Most modern languages have modules for handling this: e.g., CGI.pm●Next step: web applications (complex/faster)Experiment●Use existing files to try new things–Remember correct #! syntax–Can be bad: runs as your username (rm ...)–Check user input–Try out new sample python CGIs●PHP file in apache/htdocs can be changed too..–Lots of samples available via GoogleFAQs●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:<port-num>–http://<localmachine>.cdf.toronto.edu:<pn> in the labs●My start/stop aren't working?–Always start/stop directly in apache/bin to make sure paths work properlyOther references●The guide on the course site●httpd.apache.org●refcards.com – Apache 1.3 reference card for printing (also other useful
View Full Document