Tutorial Shengdong Zhao (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) 1 st 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, streams: 1.3.x (very popular) & 2.x (current)
Apache Architecture
Apache Architecture Select module handler at install Modules hook into phases in the Core processing 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
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.
GET / HTTP/1.1 Host: User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv: ) Gecko/ Firefox/ 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 ,utf-8;q=0.7,*;q=0.7 Keep-Alive: 300 Connection: keep-alive Cookie: … HTTP/1.x 200 OK Date: Tue, 10 Jul :47:16 GMT P3P: policyref=" 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 :47:15 GMT; path=/ Set-Cookie: … Connection: close Transfer-Encoding: chunked Content-Type: text/html; charset=utf-8 Content-Encoding: gzip
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
Apache on CDF We run instances of the Apache server daemon (httpd) using our own config files (no install!) – version – course web page student guide Apache 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 –xvzf apache.tar.gz) 4 – cd ~/309/apache/bin;./start.sh This starts the server; stop it using./stop.sh 5 – verify: ps –u | grep httpd 6 – view: lynx /
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: html files E.g. – see examples in each directory and play around
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/your/docs Can set your web admin s –ServerAdmin
Demo
Work at home 1. Install and config Cygwin 2. Double click Cygwin icon to start 3. Type “startx” to start x window 4. At the popup xterm, type “ssh -X to login to your account
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? – – in the labs My start/stop aren’t working? –Always start/stop directly in apache/bin to make sure paths work properly
Other references The student guide on the course site httpd.apache.org (e.g.) – – chttp://httpd.apache.org/docs/1.3/howto/auth.html#basi c Refcards.com – Apache 1.3 reference card for printing (also other useful cards) refcard-a4.pdf refcard-a4.pdf
.htaccess files 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 format order allow, deny deny from deny from Allow from all AuthUserFile / user/local/you/safedir/.htpasswd AuthGroupFile /dev/null AuthName EnterPassword AuthType Basic Require user wsabstract