WWW Servers

Document Sample
WWW Servers Powered By Docstoc
					              WWW Servers

                         Miroslav Milinovic
          Croatian Academic and Research Network - CARNet
                           Zagreb, Croatia
                          <miro@srce.hr>



5th CEENet Workshop on Network Technology, Budapest, Hungary, August 1999.



                              MM-WWW3/1
                              Content
•   How WWW works?
•   What is the WWW server?
•   Apache
     – directory structure; configuration files & directives; running
     – access control; authentication
     – Common Gateway Interface (CGI); passing data
     – Server side includes (SSI)
     – API: modules & handlers
     – virtual servers
•   Log analysis tools
•   Sources
•   Future


                                 MM-WWW3/2
               How WWW works?
                        Internet      WWW servers



                        (WWW)

users browse


                                      
                                       HTML files

                 authors write HTML
                                               
                        MM-WWW3/3
How WWW works?

            HTTP
HTML




   URL


       MM-WWW3/4
      What is the WWW server?
•   general purpose data delivery vehicle
•   a program (daemon, httpd):
    –   responds to an incoming TCP connection
        and provides a service to the client
    –   runs independently
•   WWW servers:
    –   do NOT validate HTML code (parse documents)
    –   do NOT check links
    –   follow MIME rules (without checking file content)

•   Web site = host + Web server + information (file system)

                              MM-WWW3/5
                          HTTP
•   application-level protocol
•   stateless (HTTP 1.0)
•   client (browser) make request - server responds
•   support for:
    –   use of URL’s
    –   Internet media types (MIME types: RFC2045-RFC2049)
•   allows access to different data formats
•   standards:
    –   HTTP 1.0 (RFC 1945), HTTP 1.1 (RFC 2068, 01.97.)

                                                             
                           MM-WWW3/6
                               HTTP

    http://info.nowhere.hr:8000/directory/file.html
    protocol   server name    port   directory/file name on the server


•    HTTP is a simple protocol:
       1. Client finds out that it should use HTTP protocol
       2. Client opens TCP connection to the server info.nowhere.hr
          on the port 8000 (or if not specified on the default port 80)




                                MM-WWW3/7
    Client - server communication
•   Simple client request (entered manually)
    telnet www.srce.hr 80
    Trying 161.53.2.69...
    Connected to regoc.srce.hr.
    Escape character is '^]'.
    GET /index.html HTTP/1.0
    ACCEPT: */*
    USER-AGENT: manually entered HTTP
    (blank line)



                                               
                          MM-WWW3/8
    Client - server communication
•   Server reply:
    HTTP/1.0 200 OK
    Date: Tue, 29 Jul 1997 12:56:15 GMT
    Server: Apache/1.1.3
    Content-type: text/html
    Content-length: 2320
    Last-modified: Fri, 22 Nov 1996 10:07:27 GMT
    (blank line)
    (content - document source)




                           MM-WWW3/9
       Request methods
Method Client           Server

GET    request          send header & data

HEAD   request          send header

POST   request & data   receive data
                        (pass to CGI script)

PUT    request & data   receive data
                        (store as requested)



                 MM-WWW3/10
                         WebDAV
•   WWW Distributed Authoring and Versioning
•   an extension of HTTP 1.1.
•   provides infrastructure for asychronous collaborative
    authoring across the Internet
•   IETF approved - November 1998
•   supported by MS and Apache
•   webDAV home page
    –   http://www.ics.uci.edu/pub/ietf/webdav/


                                                            
                             MM-WWW3/11
                    WebDAV
        client                    server
                        LOCK
                      PROPFIND
       File Open
                        GET
time




                        PUT
       File Save


                      UNLOCK
       File Close

                     MM-WWW3/12
             Server status codes
•   Status codes are three digit numbers grouped as
    follows:
        1xx - informational
        2xx - client request successful
               200 - OK
        3xx - request redirected
        4xx - client errors (request incomplete)
               403 - Forbidden
               404 - Not found
        5xx - server errors

                           MM-WWW3/13
            WWW server software
•   traditionally freely available
•   for most of the platforms:
    –   UNIX, Ms Windows, Macintosh, VMS, VM, …
•   list of available servers software:
    –   http://www.yahoo.com/Computers_and_Internet/Software/Internet/World_Wide_Web/Servers/

•   Web Server Survey
    –   http://www.netcraft.com/Survey/
•   popular server programs:
    –   CERN, NCSA (first ones)
    –   Apache, MS IIS, Netscape servers, ...

                                   MM-WWW3/14
                            Apache
•   A PAtCHy server is a kind of a plug-in replacement for
    NCSA httpd
•   under constant development
•   freely available:
     – in source code
     – binaries for many platforms (v. 1.3.x includes also the Windows NT)
     – supports HTPP 1.1. from 1.2.
•   useful addresses:
     – Apache home: http://www.apache.org/
     – http://www.apacheweek.com/
     – NCSA httpd documentation: http://hoohoo.ncsa.uiuc.edu/
     – support via Usenet: comp.infosystems.www.servers.unix

                              MM-WWW3/15
       Where to put the server?
•   server should run where information is been created
•   choose host carefully
•   give an DNS alias name to the selected host
    (www. mydoimain.mycuntry)
•   ServerRoot, DocumentRoot and Log files
    directories should be chosen carefully according to
    rules for all daemons and disk space requirements
•   User Home Pages?
•   CGI rules!


                        MM-WWW3/16
      Apache directory structure
•   can be designed (changed) during installation
    (compilation) process
•   some important directories:
    –   cgi-bin/ - CGI scripts directory (examples present)
    –   conf/ - configuration files for httpd server
    –   htdocs/ - main directory for documents
    –   logs/     - directory with log files (currently empty)
    –   other stuff (bin/, sbin/, src/, man/…)




                               MM-WWW3/17
      Apache configuration files
•   look in conf/ directory:
     – access.conf - access configuration
     – httpd.conf - server configuration
     – mime.types - MIME type to extensions definition
     – srm.conf - resource configuration
     – *.*-dist - distribution templates

    – since v.1.3.6. it is recommended to use only main
      configuration file httpd.conf

                        MM-WWW3/18
    Apache configuration directives
•   general rules:
     – case insensitive (not true for file/directory names)
     – comment lines begin with #
     – one directive per line
     – each line of these files consists of:
     – directive data [data2 ... datan]
     – extra whitespace is ignored



                         MM-WWW3/19
                           httpd.conf
•   ServerType standalone
•   Port 80
•   User nobody
•   Group nogroup
•   ServerAdmin your_e-mail_address
•   ServerRoot /home/httpd/
•   ErrorLog /home/httpd/logs/error_log
•   TransferLog /home/httpd/logs/access_log
•   PidFile /home/httpd/logs/httpd.pid
•   more directives:
    –   Keep Alive, Spare Servers, Proxy, Cache, Virtual Servers, ...

                                                                        
                                MM-WWW3/20
              httpd.conf (srm.conf)
•   DocumentRoot /home/httpd/htdocs/
•   UserDir public_html
•   DirectoryIndex index.html
•   AccessFileName .htaccess
•   DefaultType text/plain
•   ScriptAlias /cgi-bin/ /home/httpd/cgi-bin/
•   more directives:
     –   Icons, Language, Handlers, ...




                                                 
                                MM-WWW3/21
          httpd.conf (access.conf)
•   defines:
    –   which types of services are allowed
    –   in what circumstances

•   <Directory dir_name> … directives … </Directory>

•   be very careful due to possible problems:
    –   operational
    –   security




                             MM-WWW3/22
                     mime.types
•   list of MIME types know to your server:
    –   format:    type/subtype      file_extension

•   files with other extension will be sent with DefaultType

•   add an entry according to your needs




                          MM-WWW3/23
    Starting and stopping Apache
•   if you selected standalone server type:
    –   simply execute the program (apachectl start)
    –   setup automated startup (during boot)
•   apachectl options: START, STOP, CONFIGTEST
•   Apache dynamically adapts to the workload
•   to stop (restart) the server use:
    –   kill command (UNIX) (pid is in httpd.pid file)
    –   apachectl stop




                              MM-WWW3/24
                    Access control
•   two levels:
    –   per-server (Global Access Configuration file) - using
        directives in httpd.conf (access.conf)
    –   per-directory (Per-directory Access Configuration file) -
        using .htaccess files (you can change this file name using
        AccessFileName directive in httpd.conf (srm.conf)
•   two ways:
    –   by user/password
    –   by host/domain




                             MM-WWW3/25
         httpd.conf (access.conf)
              DocumentRoot settings
<Directory /home/httpd/htdocs>
   –    instead of the Directory it is possible to use
        Location (controls URL’s) or Files (controls files).
   –    it is possible to use wild cards here: * ?
Options Indexes FollowSymLinks
   –   Option can be: FollowSymLinks, SymLinksIfOwnerMatch,
       ExecCGI, Includes, Indexes, IncludesNoExec, All, None
AllowOverride All
   –   Specify which Options can be overridden by per-directory
       access files
</Directory>

                            MM-WWW3/26
          httpd.conf (access.conf)
                    Scripts directory
<Directory /home/httpd/cgi-bin>
 Options FollowSymLinks
 AllowOverride None
</Directory>
•   the later directives (according to the order in the configuration
    files) are the more important (specific)
•   if permitted the more specific are the settings in the .htaccess




                             MM-WWW3/27
User/password authentication (1)
•   Create a file called .htaccess in required directory
    (of course you can do this on the server level)

       AuthUserFile /home/httpd/admin/.htpasswd
       AuthGroupFile /dev/null
       AuthName ByPassword
       AuthType Basic
       <Limit GET>
       require user username
       </Limit>

                                                           
                         MM-WWW3/28
    User/password authentication (2)
•   using htpasswd command create the password file:
     htpasswd -c /home/httpd/bin/.htpasswd username
•   enter password of your choice (later you can check the content of
    .htpasswd file)

•   multiple users (of course you have to create entries in .htpasswd file)
     – add users in require directive in .htaccess
                             OR
     – create a group file (.htgroup), use directives AuthGroupFile and
       require group in .htaccess file
                             OR
     – use require valid-user directives (all users from .htpasswd have
       access)

                                MM-WWW3/29
                  It works, but ...
•   server asks browser for user/password to allow access
•   password is send over the network not encrypted but
    "uuencoded"
•   password is not visible in the clear, but can easily be
    decoded by anyone who happens to catch the right
    network packet (“sniffers in action”)
•   this method of authentication is as safe as telnet-style
    username and password security



                         MM-WWW3/30
     Host/domain authentication
•   protective: .htaccess file looks like

    <Limit GET>
     order deny,allow
     deny from all
     allow from hostname/domain
    </Limit>



                                            
                          MM-WWW3/31
     Host/domain authentication
•   open: .htaccess file looks like

    <Limit GET>
     order allow,deny
     allow from all
     deny from hostname/domain
    </Limit>




                          MM-WWW3/32
                    Access control
•   it is possible to use authentication by host/domain
    and by user/password together

•   for better security compile the Apache with the SSL
    (Secure Socket Layer)
    –   then server and client exchange the keys on the beginning
        of the session and all of the transactions are encrypted




                            MM-WWW3/33
Common Gateway Interface (CGI)
 •   WWW server is able to communicate with other
     programs (CGI scripts)
 •   CGI scripts can be written in any programming
     language (shell script, PERL, C, …)
 •   CGI scripts can use CGI environment variables
 •   CGI is used for:
         • getting input from user, forms processing, returning any kind of
            dynamic information, gateways to other services, ...
 •   workload is on the servers side (be careful)

                                                                          
                                MM-WWW3/34
                                CGI
•   server needs to be configured for CGI operation to
    enforce security procedures:
    ScriptAlias /cgi-bin/ /home/httpd/cgi-bin/
•   all of the files in /cgi-bin/ are considered to be a
    executable scripts (regardless of the name of the file)
•   security measures (with CGI scripts):
    –   parse and check user input
    –   programs should have only the power they require
    –   dynamically generated programs are not permitted
    –   carefully examine all cgi scripts (do not allow users to
        execute their own programs)

                              MM-WWW3/35
    Passing data (GET method)
•   data is simply attached to the end of the URL
    –   ? is used to separate data from URL (http://url?data)
    –   CGI programs are executed with URL address:
         http://www_server/cgi-bin/program_name?data

•   simple example: <ISINDEX> tag
    –   browser asks for input from user and attaches it to the URL
    –   the input is rewritten by browser (spaces become "+", \n
        become "&", …)
    –   server puts part of URL after "?" in to the environment
        variable QUERY_STRING


                             MM-WWW3/36
    Passing data (POST method)
•   recommended method for processing FORMS
•   on the HTML page with form you declare which script will be called
    to process data from the form:
     <FORM METHOD=”POST” ACTION=”/cgi-bin/script_name”>
     ...
     </FORM>
•   when user hits the submit button client contacts server and passes
    request (POST /cgi-bin/script_name) with data from the form (data
    follows URL as a document)
•   to pass the data to the CGI program server uses environment
    variables and “stdin”


                                                                   
                             MM-WWW3/37
    Passing data (POST method)

•   server executes the CGI script and provides it with:
     – list of environment variables
     – input stream of FORM contents in name=value pairs
        (name1=value1&name2=value2&name3=value3&…)
•   script knows how long this input stream is from environmental
    variable CONTENT_LENGHT
•   CGI script general procedure order:
     – read input from “stdin”
     – split name=value pairs and do value conversion (spaces, ...)
     – do something and print out results in HTML form to”stdout”

                                                                  
                            MM-WWW3/38
    Passing data (POST method)

•   CGI scripts are responsible for formatting output on
    "stdout" back to the server (finally server will pass
    this information to the client)
•   CGI script is responsible for generating content
    specific headers and send them as a first lines of
    output to the server
    –   for example:
         Content-type: text/plain
         FOLLOWED BY (at lest) ONE BLANK LINE !




                               MM-WWW3/39
        Server side includes (SSI)
•   server can be configured to scan documents with
    shtml extension for occurrence of construction like:
    <!--#command tag1="value1" tag2="value2" -->
    and replace them with the result of the command
•   this concept is used to add:
    –   current date, any other CGI environment variable value
    –   document's (or other file's) last modification data, size
    –   inline other document contents into the current document
    –   result of work of any other program on any Web server side



                            MM-WWW3/40
        API: modules & handlers
•   Apache breaks down clients request handling into a
    series of steps:
    –   URL --> Filename translation
    –   Auth ID checking
    –   Auth access checking
    –   Access checking other than above Auth
    –   Determining MIME type of the object requested
    –   `Fixups' - if needed
    –   Actually sending a response back to the client
    –   Logging the request

                                                         
                            MM-WWW3/41
       API: modules & handlers
•   on any of those steps you may tide up an handler
    (the procedure)
•   a set of handlers may make an module, eg.: cgi
    module, log module, server side includes module,
    access module, ...
•   consistent specification of the steps allows to connect
    own modules to Apache which replace the old one or
    gives the new possibilities




                         MM-WWW3/42
                 Virtual servers
•   one server may listen on many hosts names - virtual
    servers (same port, different hostnames)
•   part of basic server configuration (httpd.conf)
    <VirtualHost hostname> … </VirtualHost>
•   each of the virtual server may have totally different
    content, configuration, separate log and error files, …

•   alternative is to run another server on a different port



                          MM-WWW3/43
                 Log analysis tools
•   servers logs access information in the file
    –   client host,
    –   date,
    –   client request,
    –   status,
    –   count of the bytes sent by server
•   it is possible (and easy) to produce many kinds of
    activity reports from that data
•   plenty of freeware log analyzers (wwwstat, analog,…)


                             MM-WWW3/44
                           Sources
•   “webwatch”:
    –   http://www.w3.org/
    –   http://www.ietf.org/
    –   http://www.hwg.org/
    –   http://www.irwa.org/
    –   http://www.apache.org/
•   books:
    –   Nancy J. Yeager, Robert E. McGrath: “Web Server
        Technology”, Morgan Kaufmann Publishers, Inc, 1996
    –   Stepher Spainhour, Valerie Quercia: “Webmaster in a
        Nutshell”, O’Rilley, 1996
    –   Ben Laurie, Peter Laurie: “Apache - The Definitive Guide”,
        O’Rilley, 1997

                             MM-WWW3/45
                          Future
•   HTTP 1.1 & WebDAV
•   CSS & XSL
•   RDF - Resource Decsription Framework
•   XML - Extensible Markup Language
•   XHTML - Extensible HTML
•   PNG - Portable Network Graphics
•   Java & Jini
•   Dial tone  Web tone
•   …
               I think there may be a world market for perhaps 5 computers”
                                               (Thomas Watson, IBM, 1943)

                                                     “The internet is a fad”
                                               (Bill Gates, Microsoft, 1981)

                            MM-WWW3/46
Questions ?




  MM-WWW3/47

				
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
views:6
posted:7/29/2012
language:
pages:47